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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Object Error 2

Status
Not open for further replies.

vbtest5

IS-IT--Management
Nov 16, 2002
37
0
0
IN
Hi,
Following is the code that I use to create object of Outlook. I have not set references since I want it to work with all versions of Outlook. But the .CreateItem method produces error. Following is the code:

Dim objOutlook As Object
Dim objOutlookMsg As Object

On Error GoTo Err_Hnd

'Instantiate an Outlook Application object.
Set objOutlook = CreateObject("Outlook.Application")

'Below line produces error!
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

objOutlookMsg.To = txtEmailID.Text
objOutlookMsg.Display

Any help?

Regards,
VJ
 
It's because you failed to declare "olMailItem
 
I'd suggest turning on Option Explicit which will help to catch errors like this
 
Hi friends,

This variable (olMailItem) is a VB constant and hence need not be declared. If I set the Reference to Outlook, then the same code works. And after setting Reference, I also checked for this constant. It does exist. Then I removed the reference to Outlook object 9.0 as I want it to work with all version. At that time it fails.

Regards,
Vilas
 
>This variable (olMailItem) is a VB constant

No, it isn't. It is provided by the Outlook library. Remove the reference to the library and the constant vanishes
 
That's exactly what I meant. I would suggest attach lower version of Outlook library and make a compile. If XP will not let do this then find NT PC to make compile. I think, at the machines with higher version the compiled application will use the higher version automatically.

Or, use numbers instead of constants but it will not save from some other issues.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top