I have a client database and whenever a new client is entered, I want this to export to Outlook as a Contact at the click of a button. This command button has the code shown below. When all the fields are complete, the code runs no problem. However, should a field be missing, eg. the person has no mobile telephone number, or no postcode, when the code is being run, it comes up with an error and stops the run being completed. I would appreciate any help from anyone!
Many Thanks.
Just1
Private Sub cmd_add_contact_to_outlook_Click()
Dim objOutlook As Outlook.Application
Dim objcontact As Outlook.ContactItem
Set objOutlook = CreateObject("Outlook.Application")
Set objcontact = objOutlook.CreateItem(olContactItem)
With objcontact
.FirstName = Me!Forename
.LastName = Me!Surname
.MobileTelephoneNumber = Me!MobileNo
.CompanyName = Me!CompanyName
.BusinessTelephoneNumber = Me!DirectLineinCo
.Business2TelephoneNumber = Me!CoTelNo
.Email1Address = Me!DirectCoEmail
.Email2Address = Me!CoEmailnh
.BusinessAddressStreet = Me!CoAddressLine1
.BusinessAddressCity = Me!CoTownorCity
.BusinessAddressState = Me!CoCounty
.BusinessAddressPostalCode = Me!CoPostcode
.WebPage = Me!CoWebsite
.Save
End With
Beep
MsgBox "Confirmed", vbInformation, "Added to Contacts"
End Sub
Many Thanks.
Just1
Private Sub cmd_add_contact_to_outlook_Click()
Dim objOutlook As Outlook.Application
Dim objcontact As Outlook.ContactItem
Set objOutlook = CreateObject("Outlook.Application")
Set objcontact = objOutlook.CreateItem(olContactItem)
With objcontact
.FirstName = Me!Forename
.LastName = Me!Surname
.MobileTelephoneNumber = Me!MobileNo
.CompanyName = Me!CompanyName
.BusinessTelephoneNumber = Me!DirectLineinCo
.Business2TelephoneNumber = Me!CoTelNo
.Email1Address = Me!DirectCoEmail
.Email2Address = Me!CoEmailnh
.BusinessAddressStreet = Me!CoAddressLine1
.BusinessAddressCity = Me!CoTownorCity
.BusinessAddressState = Me!CoCounty
.BusinessAddressPostalCode = Me!CoPostcode
.WebPage = Me!CoWebsite
.Save
End With
Beep
MsgBox "Confirmed", vbInformation, "Added to Contacts"
End Sub