Item Change

The ItemChange event occurs when an item in an Items collection object is changed, either by user action or program code. Continuing the example of the Customers folder described earlier, the following code writes a record to a SQL Server 7 database when an item changes in the Customers public folder. The StrClean function in the following procedure removes single quotes that could cause an error when the SQL statement executes:

Private Sub colCustomersltems_ltemChange(ByVal Item As Object) Dim objCont As Outlook.Contactltem Dim strSQL As String Const strSep = "',"'

Dim conDB As New ADODB.Connection Set objCont = Item

If objCont.MessageClass <> "IPM.Contact.Customer" Then

Exit Sub End If

On Error GoTo AddContact_Error conDB.Open "Nwind", "sa",""

strSQL = "Insert Customers Values ("'

strSQL = strSQL & StrClean(objCont.Account & strSep strSQL = strSQL & StrClean(objCont.CompanyName) & strSep strSQL = strSQL & StrClean(objCont.FullName) & strSep strSQL = strSQL & StrClean(objCont.JobTitle) & strSep strSQL = strSQL & StrClean(objCont.BusinessAddress) & strSep strSQL = strSQL & StrClean(objCont.BusinessAddressCity) & strSep strSQL = strSQL & StrClean(objCont.BusinessAddressState) & strSep strSQL = strSQL & StrClean(objCont.BusinessAddressPostalCode) & strSep strSQL = strSQL & StrClean(objCont.BusinessAddressCountry) & strSep strSQL = strSQL & StrClean(objCont.BusinessTelephoneNumber) & strSep strSQL = strSQL & StrClean(objCont.BusinessFaxNumber) & "')" conDB.Execute strSQL conDB.Close

AddContact_Exit: Exit Sub


Utility. ErrorTrap 'Writes error to event log or file Resume AddContact_Exit End Sub

Was this article helpful?

0 0

Post a comment