Referencing fields of outlook using VBA (1 Viewer)

Samantha

still learning...
Local time
Today, 12:28
Joined
Jul 12, 2012
Messages
180
So in my access database I have created a contact form and it has an on-click event that creates a record in outlook. (by the way I removed linking because it was causing slow responses and not responding) My hang-up is referencing the Display as: and File As: fields (Which file as populates itself last, first but I would like to to automatically include the company name in "()"). I found other code using .EmailDisplayAs however it throws up an error number 438, and says object doesn't support this property of method. Heres my code.

Private Sub cmdSaveToOutlook_Click()
On Error GoTo Error_Handler
Const olContactItem = 2
Dim olApp As Object
Dim Ctct As Object

Set olApp = CreateObject("Outlook.Application")
Set olContact = olApp.CreateItem(olContactItem)

With olContact
.FirstName = Me.First
.LastName = Me.Last
.JobTitle = Me.Job_Title
.CompanyName = Me.Company
.BusinessAddressStreet = Me.Address
.BusinessAddressCity = Me.City
.BusinessAddressState = Me.State
.BusinessAddressCountry = "USA"
.BusinessAddressPostalCode = Me.Zip_Postal_Code
.BusinessTelephoneNumber = Me.Phone
.BusinessFaxNumber = Me.Business_Fax
.Email1Address = Me.E_mail_address
.EmailDisplayAs = Me.DisplayAs
.MobileTelephoneNumber = Me.Mobile_Phone
.Display 'use .Display if you wish the user to see the contact pop-up .Save to save
End With

Error_Handler_Exit:
On Error Resume Next
Set olContact = Nothing
Set olApp = Nothing
End

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: AddOlContact" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Sub

Thanks for looking!
Samantha :confused:
 

Samantha

still learning...
Local time
Today, 12:28
Joined
Jul 12, 2012
Messages
180
Okay I figured out one reference that was wrong, it should have been .Email1DisplayName
Now I just need to figure out how to get the File as to incorporate the Company Name also?
 

Users who are viewing this thread

Top Bottom