Get Value of a Custom Field

K

Kathy Drungilas

I have a task form with a user-defined field ("Implementer") on a new
page(Environmental Info). The field contains text of a user's name. I want
to select tasks where this field is not blank, then send the task to the
name of the person in the field. [Forgive my VBA skills, as a beginner I
still feel like I'm learning a foreign language.]

I receive an run-time error, "91" Object variable or With block not set" on
my Set taskSafeRecip = _ plantTask.UserProperties("Implementer") line. Am I
referencing my custom field correctly? or doing something else wrong?

Sub AssignEnvironmentalPlantTasks()

Dim objApp As Outlook.Application
Dim objNS As NameSpace
Dim objMe As SafeCurrentUser 'Redemption object
Dim plantTasks As MAPIFolder
Dim plantTask As TaskItem
Dim taskSafeRecip As Redemption.SafeRecipient
'Dim strResponsible As String

'reference the mailbox folder to work with
Set objNS = Application.GetNamespace("MAPI")
Set plantTasks = objNS.GetDefaultFolder(olFolderTasks)
Set taskSafeRecip = plantTask.UserProperties("Implementer")

'Loop through all Tasks in Tasks Folder
For Each plantTask In plantTasks.Items
If plantTask.DelegationState = olTaskNotDelegated Then
plantTask.Assign
' Set tskResponsible = plantTask.Recipients.Add("strResponsible")
Set tskResponsible = plantTask.Recipients.Add("taskSafeRecip")
MsgBox "Assigning Plant Tasks, please wait"
'safely resolve recipient addresses
taskSafeRecip.Resolve
plantTask.Send
End If
Next

Set plantTask = Nothing
Set plantTasks = Nothing
Set objNS = Nothing

End Sub



Kathy Drungilas--
to answer via email, remove [nospam] from address
 
S

Sue Mosher [MVP]

For one thing, you're trying to set a SafeRecipient object to a UserProperty object. That's not going to work.

The other possible issue is -- how did you add the field to the form? Does the field appear on the User-defined Fields in This Item list under All Fields? If not, drag it from the Field Chooser to any blank page on your form; you can delete the resulting control.

Then try:

Dim myProp as UserProperty
On Error Resume Next

myProp = plantTask.UserProperties("Implementer")
If myProp <> "" Then
' it's not blank
End If

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm
 
K

Kathy Drungilas

Thanks Sue--I do see the error you pointed out in setting the recipient
object to the user property. I haven't yet worked out how to engage
Redemption on the code, but I have made a couple other changes so that it is
now assigning the task to the name in the "Implementer" field. (The field
was already added to the form and listed in the user-defined fields for the
folder.) My revised code is below.

Dim objApp As Outlook.Application
Dim objNS As NameSpace
Dim objMe As SafeCurrentUser 'Redemption object
Dim plantTasks As MAPIFolder
Dim plantTask As Outlook.TaskItem
Dim taskSafeRecip As Redemption.SafeRecipient

'reference the mailbox folder to work with
Set objNS = Application.GetNamespace("MAPI")
Set plantTasks = objNS.GetDefaultFolder(olFolderTasks)

'Loop through all Tasks in Tasks Folder
For Each plantTask In plantTasks.Items
If plantTask.DelegationState = olTaskNotDelegated Then
Dim myProp As UserProperty
Set myProp = plantTask.UserProperties("Implementer")
If myProp <> "" Then
' it's not blank
End If
With plantTask
plantTask.Assign
Set myDelegate = plantTask.Recipients.Add(myProp)
On Error Resume Next
plantTask.Send
End With
End If
Next

Set plantTask = Nothing
Set plantTasks = Nothing
Set objNS = Nothing

kathy drungilas

For one thing, you're trying to set a SafeRecipient object to a UserProperty
object. That's not going to work.

The other possible issue is -- how did you add the field to the form? Does
the field appear on the User-defined Fields in This Item list under All
Fields? If not, drag it from the Field Chooser to any blank page on your
form; you can delete the resulting control.

Then try:

Dim myProp as UserProperty
On Error Resume Next

myProp = plantTask.UserProperties("Implementer")
If myProp <> "" Then
' it's not blank
End If

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm




Kathy Drungilas said:
I have a task form with a user-defined field ("Implementer") on a new
page(Environmental Info). The field contains text of a user's name. I want
to select tasks where this field is not blank, then send the task to the
name of the person in the field. [Forgive my VBA skills, as a beginner I
still feel like I'm learning a foreign language.]

I receive an run-time error, "91" Object variable or With block not set" on
my Set taskSafeRecip = _ plantTask.UserProperties("Implementer") line. Am I
referencing my custom field correctly? or doing something else wrong?

Sub AssignEnvironmentalPlantTasks()

Dim objApp As Outlook.Application
Dim objNS As NameSpace
Dim objMe As SafeCurrentUser 'Redemption object
Dim plantTasks As MAPIFolder
Dim plantTask As TaskItem
Dim taskSafeRecip As Redemption.SafeRecipient
'Dim strResponsible As String

'reference the mailbox folder to work with
Set objNS = Application.GetNamespace("MAPI")
Set plantTasks = objNS.GetDefaultFolder(olFolderTasks)
Set taskSafeRecip = plantTask.UserProperties("Implementer")

'Loop through all Tasks in Tasks Folder
For Each plantTask In plantTasks.Items
If plantTask.DelegationState = olTaskNotDelegated Then
plantTask.Assign
' Set tskResponsible = plantTask.Recipients.Add("strResponsible")
Set tskResponsible = plantTask.Recipients.Add("taskSafeRecip")
MsgBox "Assigning Plant Tasks, please wait"
'safely resolve recipient addresses
taskSafeRecip.Resolve
plantTask.Send
End If
Next

Set plantTask = Nothing
Set plantTasks = Nothing
Set objNS = Nothing

End Sub



Kathy Drungilas--
to answer via email, remove [nospam] from address
 
S

Sue Mosher [MVP]

This is what you have now:

Set myProp = plantTask.UserProperties("Implementer")
If myProp <> "" Then
' it's not blank
End If

Note that myProp is an object. If it doesn't already exist on the item, you're going to get an error. You might need to use:

Set myProp = plantTask.UserProperties("Implementer")
If not MyProp Is Nothing Then
If myProp.Value <> "" Then
' it's not blank
End If
End If

See the difference?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
K

Kathy Drungilas

That makes sense! I do see the difference--although in my case every task
will have an "Implementer", I will still adjust my code.
THANKS!
KD
This is what you have now:

Set myProp = plantTask.UserProperties("Implementer")
If myProp <> "" Then
' it's not blank
End If

Note that myProp is an object. If it doesn't already exist on the item,
you're going to get an error. You might need to use:

Set myProp = plantTask.UserProperties("Implementer")
If not MyProp Is Nothing Then
If myProp.Value <> "" Then
' it's not blank
End If
End If

See the difference?
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 

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