Outlook autofill code faulting

K

Kage_

Hello everyone

I have a custom form that I have designed to auto fill custome
information. I found a code example at Windows IT Pro and it work
great, but for some reason the code has developed a bug

The user enters a contact into the field and then clicks a button o
saves the form the code tries to match the contact and auto fil
several fields including the phone number, pager number, cell numbe
etc. The problem occures if the user enters a contact that is not i
the contact database the script will fault. I have tried to find th
orginal code and article on WITPro, but I have been unable to. Als
the orginal article was written by Sue Mosher

Here is the code as I am running it when the user clicks the contac
info button

'This section will excecute upon click of th
'Customer Information butto

Sub CustomerInfoButton_Click(

Dim colLink
Dim objLin
Dim objContac

Set colLinks = Item.Link
If colLinks.Count > 0 The
Set objLink = colLinks.Item(1
Set objContact = objLink.Ite
If Not objContact Is Nothing The
Item.UserProperties("CompanyField") =
objContact.CompanyNam
Item.UserProperties("SiteField") =
objContact.Departmen
Item.UserProperties("PhoneNumberField"
=
objContact.BusinessTelephoneNumbe
Item.UserProperties("PagerNumberField"
=
objContact.PagerNumbe
Item.UserProperties("CellPhoneField")

objContact.MobileTelephoneNumbe
Item.UserProperties("CustomerNotes") =
objContact.Bod
End I
End I

Set objContact = Nothin
Set objLink = Nothin
Set colLinks = Nothin

End Su

According to the debuger it's faulting at "Set objContact
objLink.Item". I know very little about VB script so I have not bee
able to figure out the problem. I'm hopping someone will be able t
see where the problem is

I am using Outlook version 2003 SP1 Build (11.6359.6360)

Thanks

Mik
 
S

Sue Mosher [MVP-Outlook]

Just add an On Error Resume Next statement after your initial Dim statements. That will avoid the error, which can occur if there is an entry in the Contacts box on the item, but it doesn't actually point to a valid contact.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top