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

Email File As Attachment 1

Status
Not open for further replies.

SgtJarrow

Programmer
Apr 12, 2002
2,937
0
0
US
Okay folks....it feels like a Friday and I am really having a hard time today.

Scenario:
Access 97 - Outlook 98
Need to send an email with an attachment.
To address is known and is available as a variable.
Attachment location is known and available as a variable.

Problem:
The following code string:

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)

produces a run-time error '13' Type Mismatch error on the

Set objOutlook = CreateObject("Outlook.Application")

line...

I need to correct this error and get this working. Any help appreciated. Thanks.

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
Just use this:

Set objOutlook = New Outlook.Application

instead of

Set objOutlook = CreateObject("Outlook.Application")
 
Robert,

Not sure if this is the problem or not, but check your references in design view and make sure "Microsoft Outlook 9.0 Object Library" (or whatever version you might show) is selected......
 
Cosmo,

Wish I could...technology here is a bit of a quandry. They don't know what they are doing and have everything all screwed up. I have the 9.0 library for everything but Outlook and can't install the dll myself due to their issues.

KarMac21,

Gave that a shot, but now I get a runtime 430 error....Class doesn't support Automation.

I am almost to the point where I am going to tell the project requestor that due to system constraints (not my own inability!!!) this can not be completed as requested. I can get DOCmd.SendObject to work great, but I just can do this with automation. But I need an attachment, and not an attachment of an object in Access....Any other suggestions???

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
Danvlas is the MAN!!!!!

If I could give you more than one star, you would have it. Thanks!

****************************
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III
MCSA, CNA, MCP, Network+, A+
w: robert.l.johnson.iii@citigroup.com
h: wildmage@tampabay.rr.com
 
Just a side note...this way you don't even need a reference to the Outlook Object libraries, which is usually the main cause for such failures. If Outlook is correctly installed and registered, it will work...

The only thing is that the 'dot-magic' won't be there for you, so you'll have to type all properties and methods.

I usually set the reference until I finish the code (I'm lazy, of course), then I remove them. Microsoft-proof...

Glad it worked [smile]




[pipe]
Daniel Vlas
Systems Consultant

 
Hi danvlas,

This was great for me to come across. I got it working but something interesting is happening.

If I use this code below making sure I have the right referernces it works just great:
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
'.To = emailadresses
'.CC = more emailadresses
'.Subject = "subject"
'.HTMLBody = ""
.Attachments.Add "C:\My Documents\TMS_example.doc", olByValue, 1, "TMS_example.doc"
.Display
End With

But if I remove the references and Dim them as Variants the attachment goes through as a link not a true attachment. I am changing nothing else but removing the reference and commenting out the ...As Outlook... part of the dim statement.

Any ideas about this?

Thanks


Remember the Past, Plan for the Future, yet Live in the Present for tomorrow may never come.
-etrain
 
Never mind I answered the question myself. Without the references it does not know what olByValue is so it appears to be defaulting to 'olByReference' which is linking it instead.
I changed olByValue to '1' and it works as intended now. I went ahead a created a variable called olByValue and set it equal to 1 for readability sake.


Remember the Past, Plan for the Future, yet Live in the Present for tomorrow may never come.
-etrain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top