Creating new Journal item in Outlook

E

elziko

Everytime I use this code:

Dim objOutlook As New Outlook.Application
Dim objNameSpace As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Dim objJournalEntry As Outlook.JournalItem =
DirectCast(objOutlook.CreateItem(Outlook.OlItemType.olJournalItem),
Outlook.JournalItem)
objJournalEntry.Subject = "TEST!"
objNameSpace = objOutlook.GetNamespace("MAPI")
objFolder =
objNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJournal)
objFolder.Items.Add(objJournalEntry)

To create a new Journal item I get the following exception:

An unhandled exception of type 'System.ArgumentException' occurred in
WindowsApplication4.exe
Additional information: Could not complete the operation. One or more
parameter values are not valid.

I'm using the Outlook 10.0 object model.

Anyone know what I'mm doing wrong. Are there some properties of a
JournalItem that MUST be completed before adding?
 
J

Jay B. Harlow [MVP - Outlook]

Elziko,
Which line are you getting that error on?

Normally what I do is get a working example in Outlook VBA, then I cut &
paste that into VB.NET making any changes as needed. (or use "Tools -
Upgrade VB6 code" available in VS.NET 2003).

This way I know its not some strange interop issue.
objFolder.Items.Add(objJournalEntry)
The Items.Add method takes the OlItemType enum which is the type of item to
CREATE or it takes a string which is the message class. It does not accept
an Outlook JournalItem.

Instead of:
Dim objJournalEntry As Outlook.JournalItem =
DirectCast(objOutlook.CreateItem(Outlook.OlItemType.olJournalItem),
Outlook.JournalItem) ...
objFolder.Items.Add(objJournalEntry)

Try:
Dim objJournalEntry As Outlook.JournalItem _
= DirectCast( _
objFolder.Items.Add(Outlook.OlItemType.olJournalItem), _
Outlook.JournalItem)

Hope this helps
Jay
 

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