This is proving to be more challenging than I expected. Via the help of this forum I have a custom appointment form and use a VBA macro to copy data from contact fields, to the default appointment fields.
How do I copy the "Company" field (from contacts) to a text box field in my custom appointment form via the VBA macro? As you can see in my code below I am already copying the "Company Name" to the Appt Subject Field. However I am unable to get this copied to the custom form field.
From what I am seeing changing a value is something like this:
MyItem.UserProperties.Find("Customer Name").Value = "objContact.CompanyName".
Sub CreateMeetingatContactLocation()
Dim oOL As Outlook.Application
Dim NS As Outlook.NameSpace
Dim objOwner As Outlook.Recipient
Dim objAppt As Outlook.AppointmentItem
Dim objAppointment As Outlook.AppointmentItem
Dim objContact As Outlook.ContactItem
Dim strPhone As String
Dim strBody As String
Set NS = Application.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("customerdb@beatonindustrial.com")
objOwner.Resolve
If objOwner.Resolved Then
'MsgBox objOwner.Name
Set newCalFolder = NS.GetSharedDefaultFolder(objOwner, olFolderCalendar)
End If
Set oOL = Outlook.Application
Set objAppt = newCalFolder.Items.Add("IPM.Appointment.Beaton Service Form 4.9")
Set objContact = oOL.ActiveExplorer.Selection.Item(1)
' Use Company for Location
If objContact.CompanyName <> "" Then
objAppt.Subject = inputdata & " , " & inputdata5 & ", " & objContact.CompanyName & ", - OR - " & objContact.FullName & " , Phone: " & objContact.BusinessTelephoneNumber & " , Cell: " & objContact.MobileTelephoneNumber
' Use Business address if available, else home address
If objContact.BusinessAddress <> "" Then
objAppt.Location = objContact.BusinessAddressStreet & "," & objContact.BusinessAddressCity & "," & objContact.BusinessAddressState & "," & objContact.BusinessAddressPostalCode
strPhone = objContact.BusinessTelephoneNumber
Else
objAppt.Location = objContact.HomeAddressStreet & ", " & objContact.HomeAddressCity & " " & objContact.HomeAddressState & " " & objContact.HomeAddressPostalCode
strPhone = objContact.HomeTelephoneNumber
MyItem.UserProperties.Find("Customer Name").Value = "objContact.CompanyName"
How do I copy the "Company" field (from contacts) to a text box field in my custom appointment form via the VBA macro? As you can see in my code below I am already copying the "Company Name" to the Appt Subject Field. However I am unable to get this copied to the custom form field.
From what I am seeing changing a value is something like this:
MyItem.UserProperties.Find("Customer Name").Value = "objContact.CompanyName".
Sub CreateMeetingatContactLocation()
Dim oOL As Outlook.Application
Dim NS As Outlook.NameSpace
Dim objOwner As Outlook.Recipient
Dim objAppt As Outlook.AppointmentItem
Dim objAppointment As Outlook.AppointmentItem
Dim objContact As Outlook.ContactItem
Dim strPhone As String
Dim strBody As String
Set NS = Application.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("customerdb@beatonindustrial.com")
objOwner.Resolve
If objOwner.Resolved Then
'MsgBox objOwner.Name
Set newCalFolder = NS.GetSharedDefaultFolder(objOwner, olFolderCalendar)
End If
Set oOL = Outlook.Application
Set objAppt = newCalFolder.Items.Add("IPM.Appointment.Beaton Service Form 4.9")
Set objContact = oOL.ActiveExplorer.Selection.Item(1)
' Use Company for Location
If objContact.CompanyName <> "" Then
objAppt.Subject = inputdata & " , " & inputdata5 & ", " & objContact.CompanyName & ", - OR - " & objContact.FullName & " , Phone: " & objContact.BusinessTelephoneNumber & " , Cell: " & objContact.MobileTelephoneNumber
' Use Business address if available, else home address
If objContact.BusinessAddress <> "" Then
objAppt.Location = objContact.BusinessAddressStreet & "," & objContact.BusinessAddressCity & "," & objContact.BusinessAddressState & "," & objContact.BusinessAddressPostalCode
strPhone = objContact.BusinessTelephoneNumber
Else
objAppt.Location = objContact.HomeAddressStreet & ", " & objContact.HomeAddressCity & " " & objContact.HomeAddressState & " " & objContact.HomeAddressPostalCode
strPhone = objContact.HomeTelephoneNumber
MyItem.UserProperties.Find("Customer Name").Value = "objContact.CompanyName"