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!

DoCmd.SendObject .... need to attach Text File ... Access97

Status
Not open for further replies.

mb22

Programmer
Sep 4, 2002
258
0
0
US
I need to attach a text file with my email using Access97. Without attaching the text file, the message goes thru okay, and I can retrieve my new message from Outlook.

Here is my statement

DoCmd.SendObject acSendModule, "Mytextfile.txt", acFormatTXT, "Mr. Bob", , , "This is the subject", "This is the message!", False

I get run-time error 2501 ... the SendObject action was cancelled. I tried the full path name of the text file
"c:\temp\Mytextfile.txt"........ still same error

How can I attach a text file..... which is not an object in my current database?

I selected the acSendModule option b'cos that was what appeared closest to a text file.

Any help?
acSendForm
acSendModule
acSendNoObject (default)
acSendQuery
acSendReport
acSendTable
 
“How can I attach a text file..... which is not an object in my current database?”

I don’t think you get to do this. Send object sends an object of the current database.

You could use the transfertext method to change your text file into a table where each row is defined as a line of text, and then you can use sendobject to send the table.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Here's the short .. try this (and see the MS Outlook Help for more info)
try this: (Assuming the text file you are looking for exists already)

dim EmailApp
Dim TheEmail

set EmailApp = createobject("outlook.Application")
Set TheEmail = emailapp.createobitem(olmailitem)
Theemail.attachments.add "C:\MyFileName.txt"
Theemail.subject = "Per your request"
Theemail.to = "Fred.Flinstone@123.com"
Theemail.body = "Here's waht you were looking for ......"

Hope this helps .. like I said, though, check out the automation portions of MS Outlook for more. Let me know if you have any other questions.

John

 
Try looking at thread705-354563

I asked this question before Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
As I said before, you can't using sendobject. I'm sure either of the two already offered solutions will work for you.

Here, for your amusement, is yet a third solution.

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

Sub CreateEMailSession()

' Create the Outlook session
Set objOutlook = CreateObject("Outlook.Application")

' create the message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

End Sub

Sub SendMessage(RecipientTo As String, RecipientCC As String, RecipientBC As
String, Subject As String, Message As String, HTMLFormat As Boolean,
DisplayMsg As Boolean, Optional AttachmentPath)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(RecipientTo)
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(RecipientCC)
objOutlookRecip.Type = olCC

'Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(RecipientBC)
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = Subject
If HTMLFormat Then
.HTMLBody = Message
Else
.Body = Message
End If
.Importance = olImportanceHigh

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Send
End If

End With

End Sub



Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
thanks guys. I will try all suggestions.

Actually what I did was....... The text file (Mytextfile.txt) was kind of a report I created by writing line by line from actions within a module. So I decided to insert the information into a table instead and create an Access report, which is easier to send with "acSendReport".

Don't know why I had wanted to avoid using a table, and having to append to it daily or deleting daily and recreating....., but maybe it is not too bad after all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top