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!

Can I attach Word doc to Email message in Access 97

Status
Not open for further replies.

richard1458

Instructor
Oct 21, 2000
27
0
0
GB
I have:
Access 97
Outlook Express 5
How can I send a file (a Word Document) as an attachment to an email generated from within Access?
(Sorry if this has been answered elsewhere - I'm sure I once came across something about this in this forum, but have searched all the key words I can think of, to no avail)
- Richard
 
Have you written the code to create the email and need just the attachment code or do you need all the code?

Does Outlook Express have an object model that can be referenced in the Tools->References menu? Kathryn


 
I just need the attachment code, I am already used to using the SendObject command, but can't find any reference to sending objects other than those which Access creates itself.
My copy of Access does not seem to have a menu item called References on the Tools menu, though it is referred to in my Access help file! So I can't answer your second question.
Look forward to getting the attachments code,
- TIA
Richard
 
OK to get to the Tools-> References menu you must be in a code module. So open up the code that contails the SendObject command and look at Tools there.

To do this, you will not use the Send Object command, you will create a reference to Outlook and create your message and attachments using this reference. Here is some sample code.

I use this to send a simple emial from Access. What this does is print a few reports and email one of my coworkers that it is ready. There is an Attachments property, that you can set to the path of your file.

*****Begin Sample Code****

Function GL1XX_Driver()

On Error GoTo DriverErr

Dim outApp As Outlook.Application
Dim outMessage As Outlook.MailItem
Dim dtmDelay As Date
Dim strName As String
Dim x As Integer
Dim blnErrors As Boolean
Dim strErrStr As String

GL1XX_Driver = RC_ABEND

For x = 1 To 6
strName = "rptGL10" & x & "_A"
DoCmd.OpenReport strName, acViewNormal
'DoCmd.OpenReport strName, acViewPreview
Next x

Set outApp = CreateObject("Outlook.application")

Set outMessage = outApp.CreateItem(olMailItem)

outMessage.To = "Jane Whitney"
outMessage.Subject = "Out of Balances are ready at the printer"
outMessage.Send

GL1XX_Driver = RC_COMPLETE



DriverExit:
On Error Resume Next
Set outMessage = Nothing
outApp.Quit
Set outApp = Nothing
Exit Function

DriverErr:
blnErrors = True
strErrStr = "Driver: " & strName & "did not print"
Call Write_Err("GL1XX", strErrStr)

Resume DriverExit
End Function


*****End Sample Code****

This should get you started. Post if you need more help. Kathryn


 
Many thanks for this. It made me realise how much I still have to learn about writing code! So here are some rather basic questions:
Does this go in the code for a form, or in a separate module?
Which bits am I going to have to change to get this working with Outlook Express? (I assume this code refers to Microsoft Outlook.)
I couldn't understand the function of the code in the For x loop, as I thought this was code for mailing a file on the hard disk, or wherever.
I did find a reference to Microsoft Outlook Express in the References, and ticked it. When I retype the line Dim outApp As ... the popup menu of choices includes 'MSOEOBJ' and 'IOEAcctWizardOM' which look as if they might have something to do with Outlook Express.
Thank you for your patience,
Richard
 
Richard,

See comments inline below:

Does this go in the code for a form, or in a separate module?
It can go in either. If you put it in a separate module, then you would just call it from the form, maybe in the onClick event. If it was in the form, the code might be included directly in the onClick event.
Which bits am I going to have to change to get this working with Outlook Express? (I assume this code refers to Microsoft Outlook.)
See below.

I couldn't understand the function of the code in the For x loop, as I thought this was code for mailing a file on the hard disk, or wherever.
Sorry, you can ignore that bit. That is where I print out a bunch of reports. The code you want is only the stuff following that sends out the email.

I did find a reference to Microsoft Outlook Express in the References, and ticked it. When I retype the line Dim outApp As ... the popup menu of choices includes 'MSOEOBJ' and 'IOEAcctWizardOM' which look as if they might have something to do with Outlook Express.
Oops, check out this link:

It sounds like to me that you shouldn't find this reference at all.

Then look at:


Again, it sounds like you can only use this code if you are on a Mac, not on a PC. To quote, you should use Outlook if "You use or plan to use Office 97 or Exchange Server and want to take advantage of the integration of Outlook with this version of the Office suite, and the integration with Exchange Server."


In summary, I don't know how you are going to do what you want to do.

Sorry to be the bearer of bad tidings. Any chance you can upgrade to Outlook 98? Kathryn
 
Oh well, it was worth a try. I suppose I could always use Outlook for the specific task that I want to use this code for. (But why do I need Outlook 98? I have 97.)
- Thanks all the same for all your advice, much appreciated,
- Richard
 
Henry,

As far as I know SendObject does not allow the use of attachments. Please let me know if it does.

Thanks. Kathryn


 
Kathryn, you are right. A SendObject rtf shows up as a Word icon in e-mail. My mistake.

Best regards,

Henr¥
 
Kathryn,
Sorry to trouble you further. Just one last question (hopefully). I am trying to use this code for Outlook but it doesn't like the line:
GL1XX_Driver = RC_ABEND (variable not defined I think)
and presumable the later one that looks similar would cause problems too. What are RC_ABEND and RC_COMPLETE?
- Richard
 
Richard,

Sorry for the delay; I took a long weekend at the beach.

The codes you are asking about are codes that we use internally here.

RC_COMPLETE = 0, RC_PENDING = 1, RC_PROCESSING = 2, RC_ABEND = 99

The db I took that code from is managed by a queuing system, which assigns one of the above statuses to every job.

For your use, you can remove the lines. Kathryn


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top