Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Outlook task user defined field from VB 1

Status
Not open for further replies.

cloverdog

Technical User
Mar 4, 2008
41
GB
Hello.
I have manually added a field called 'TestField' to Outlook2003 Tasks. I would like to be able to create a task from MS Access using VB and set the value of some fields including the user defined field. The code I am using sucessfully creates the task and sets a built in field, if I remove the line setting the UDF.

Could anyone please point out where I am going wrong and tell me how to set the UDF please.

The code I am using is:

Sub CreateTask()

Dim olApp As Outlook.Application
Dim olTsk As TaskItem

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
.Subject = "Test task creation"
.olTsk.UserProperties("TestField") = "not working"
.Save

End With

Set olTsk = Nothing
Set olApp = Nothing
End Sub

Thank you in advance for any help.
 
You're already using a with construct, remove the reference within it to the task item...
Code:
With olTsk
        .Subject = "Test task creation"
        .UserProperties("TestField") = "not working"
        .Save
        
    End With

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Having a quick test you'd also have to add the userproperty to the taskitem, something like:
Code:
With olTsk
        .Subject = "Test task creation"
        [red].UserProperties.Add "TestField", olText[/red]
        .UserProperties("TestField") = "not working"
        .Save
        
    End With
Hope this helps

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Thank you Harley.

Once again I discover the joys of the cut and paste error whilst simplifying from the original subroutine where it was outside of the WHERE statement.

The thing I really didn't get was adding the field to the ITEM. It now works - I don't know why it works - but it works.

Thank you for your quick and helpful response.
 
The reason you need to add to the UserProperties collection is that the new task item has no UserProperties in the collection associated with it, so setting the UserProperty without adding it will have no effect as the item won't be found in the collection.

Anyway, glad you got it sorted and thanks for the star [smile]

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top