How do populate user defined fields with parsed string from an incoming email?

B

Ben Lawless

Hello,

I am trying to populate three user defined fields in my Inbox folder
with strings that I parse from an incoming email that meets a certain
criteria.

I am able to parse the three strings at the time the email comes in, but
I am not able to assign them to their respective columns in their Inbox
folder.

Here is my code so far:

Sub CustomMailMessageRule(Item As Outlook.MailItem)

Dim myOlApp As Outlook.Application
Dim strDueDate As String
Dim strPriority As String
Dim blnInitialResponse As Boolean
Dim strInitialResponse As String
Dim myUserProperty As Outlook.UserProperty
Dim myUserPropertyTwo As Outlook.UserProperty
Dim myUserPropertyThree As Outlook.UserProperty
On Error Resume Next

'Get Due Date from email body
strDueDate = ResponseMacro.ParseDueDate("Requested Completion
Date.+\s", Item.Body)
strDueDate = Trim(strDueDate)
If strDueDate = "" Then
strDueDate = "None"
End If
Set myUserProperty = Item.UserProperties.Add("Date Due", olText)
Set myUserProperty.Value = strDueDate
myUserProperty.AddToFolderFields

'Get Priority from email body
strPriority = ResponseMacro.ParsePriority("Priority.+\s", Item.Body)
strPriority = Trim(strPriority)
If strPriority = "" Then
strPriority = "N/A"
End If
Set myUserPropertyTwo = Item.UserProperties.Add("Priority Lvl",
olText)
Set myUserPropertyTwo.Value = strPriority
myUserPropertyTwo.AddToFolderFields

'Set Inital Response sent to True
blnInitalResponse = False
strInitialResponse = CStr(blnInitalResponse)
Set myUserPropertyThree = Item.UserProperties.Add("Initial Sent",
olText)
Set myUserPropertyThree.Value = strInitialResponse
myUserPropertyThree.AddToFolderFields

myOlApp.Close olSave

MsgBox "Running script" & " _ " & strDueDate & " _ " & strPriority &
" _ " & strInitialResponse

End Sub

The Msg Box is just used to verify that the strings are being captured
and that the values are correct. Any help would be appreciated.

Thanks!
 
K

Ken Slovak - [MVP - Outlook]

Set is used only for objects, not for properties.

Try:
myUserProperty.Value = strDueDate
 
B

Ben Lawless

So, here is the code now:

Sub CustomMailMessageRule(Item As Outlook.MailItem)

'notice that this is being run from a rule script

Dim myOlApp As Outlook.Application
Dim strDueDate As String
Dim myUserProperty As Outlook.UserProperty
On Error Resume Next

'Get Due Date from email body. Calls an external function
strDueDate = ResponseMacro.ParseDueDate("Requested Completion
Date.+\s", Item.Body)
strDueDate = Trim(strDueDate)
If strDueDate = "" Then
strDueDate = "None"
End If
myUserProperty = Item.UserProperties.Add("Date Due", olText)
myUserProperty.Value = strDueDate
myUserProperty.AddToFolderFields

myOlApp.Close

MsgBox "Running script" & " " & strDueDate ' & " _ " & strPriority &
" _ " & strInitialResponse

End Sub

It is still not populating the fields that are being created in my
inbox.

Is there something that I am missing? Most likely :)

Any help appreciated.

Thanks,
Ben
 
K

Ken Slovak - [MVP - Outlook]

Please post parts of the preceding thread in your messages, that interface
you are using doesn't do that and it makes it very hard to follow things.

Set myUserProperty = Item.UserProperties.Add("Date Due", olText)

You use Set to instantiate objects. You don't use set when you set a value
for the objects that you've instantiated. I'd suggest looking over the form
code samples at www.outlookcode.com to get a handle on the basic syntax you
need to use for Outlook coding.
 

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