Li Pang,
As I requested: You need to include *all* the text from Exception.ToString
not ex.Message, you need:
| Catch ex As System.Exception
| Debug.WriteLine("ERROR: " & ex.ToString())
| End Try
Cut & paste all the lines that the Debug.WriteLine produces...
This will better help identify where specifically the problem is.
Hope this helps
Jay
"Li Pang" <Li****@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
| Jay,
|
| I didn't use Option Strict On because it causes other validation. I have
| only one single problem to pass message ID from CDO to Outlook.
| the id is a long string like
|
0000000043A5913410C2B848A9ECF84FFE693BF40700C8C0B8 F6F0E3D211BAC00008C7C9AA8C00001E9052E900000030C812 DEF7FC4CBDA6B42C363192E300000027962A0000
|
| and exception after the line
|
| Try
| oMsg =
|
Outlook.Session.GetItemFromID("0000000043A5913410C 2B848A9ECF84FFE693BF40700C8C0B8F6F0E3D211BAC00008C 7C9AA8C00001E9052E900000030C812DEF7FC4CBDA6B42C363 192E300000027962B0000")
| Debug.WriteLine("OK")
| Catch ex As System.Exception
| Debug.WriteLine("ERROR: " & ex.Message)
| End Try
|
| is "Specified cast is not valid"
|
| This error persists by using DirectCast in your codes.
|
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Li,
| > Yes:
| >
| >
http://msdn.microsoft.com/library/de...ty_message.asp
| >
| > Are you getting a compile error or a runtime error? My sample addresses
| > compile errors (caused by Option Strict On).
| >
| > If you are getting a runtime error, can you show the entire exception
| > (Exception.ToString) to better identify the problem.
| >
| > Hope this helps
| > Jay
| >
| > "Li Pang" <Li****@discussions.microsoft.com> wrote in message
| > news:BF**********************************@microsof t.com...
| > | Jay,
| > |
| > | Thank for your help. But I still got the same error. Are you sure the
ID
| > is
| > | a string?
| > |
| > | "Jay B. Harlow [MVP - Outlook]" wrote:
| > |
| > | > Li,
| > | > Do you have Option Strict On?
| > | >
| > | > If you have Option Strict On:
| > | > - cdoMsg.ID has a return type of Object (which contains a String)
| > | > - Session.GetItemFromID also has a return type of Object (which
based on
| > the
| > | > ID, may contain a MailItem)
| > | >
| > | >
| > | > Try something like:
| > | >
| > | > Dim outlookApp As Microsoft.Office.Interop.Outlook.Application
| > | >
| > | > | Dim outlookMsg AsMicrosoft.Office.Interop.Outlook.MailItem
| > | > | Dim cdoMsgAs MAPI.Message
| > | >
| > | > | outlookMsg = DirectCast( _
| > | > outlookApp .Session.GetItemFromID( _
| > | > DirectCast(cdoMsg.ID, String) _
| > | > ), Outlook.MailItem)
| > | >
| > | > Which tells the compile that cdoMsg.ID returns a String, and
| > | > Session.GetItemFromID returns an Outlook.MailItem.
| > | >
| > | > Hope this helps
| > | > Jay
| > | >
| > | >
| > | > "Li Pang" <Li****@discussions.microsoft.com> wrote in message
| > | > news:7B**********************************@microsof t.com...
| > | > | Hi,
| > | > |
| > | > | I used following codes to pass a message item from CDO to Outlook.
| > They
| > | > | worked fine when I used outlook 2000, but get an error of
"Specified
| > cast
| > | > is
| > | > | not valid." when I used Outlook 2003. Anybody has an ideal?
| > | > |
| > | > | Dim outlookMsg AsMicrosoft.Office.Interop.Outlook.MailItem
| > | > | Dim adoMsg As MAPI.Message
| > | > | outlookMsg =
| > | > |
| > | >
| >
Microsoft.Office.Interop.Outlook.Application.Sessi on.GetItemFromID(cdoMsg.ID)
| > | > |
| > | > |
| > | >
| > | >
| > | >
| >
| >
| >