Outlook user property

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am trying to open a new outlook message and add a user defined property to
it, from within MS Access using the below code. I am getting an 'Object
variable or With block variable not set' error on the highlighted line. What
am I doing wrong?

Thanks

Regards

' MS Access code follows

Private WithEvents objOutlook As Outlook.Application
Private WithEvents objOutlookMsg As Outlook.MailItem

Sub NewMail()
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

eto = "(e-mail address removed)"
esubject = ""

Email_ID = GetGUID

Dim x As UserProperty

x = objOutlookMsg.UserProperties.Add("CompanyID", olText) ' <=== error
on this line
objOutlookMsg.UserProperties.Item("CompanyID").Value = Str(Me.ID)

objOutlookMsg.To = eto
objOutlookMsg.Display
End Sub
 
YOu need to use the Set keyword with that statement, since it returns a
UserProperty object. You can then use that object:

x.Value = Str(Me.ID)
 
Back
Top