Error Code when field is empty... (1 Viewer)

Just1

Registered User.
Local time
Today, 10:43
Joined
Jan 9, 2005
Messages
50
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
 

rainman89

I cant find the any key..
Local time
Today, 13:43
Joined
Feb 12, 2007
Messages
3,015
try the nz() function
Code:
=NZ (Me!CoPostcode)
 

Just1

Registered User.
Local time
Today, 10:43
Joined
Jan 9, 2005
Messages
50
Thanks, that worked!

Just1
 

Users who are viewing this thread

Top Bottom