View Full Version : Error Code when field is empty...


Just1
04-17-2007, 12:07 PM
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
04-17-2007, 12:18 PM
try the nz() function

=NZ (Me!CoPostcode)

Just1
04-17-2007, 01:40 PM
Thanks, that worked!

Just1

rainman89
04-17-2007, 01:44 PM
glad to help-