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

Attach a document to e mail via code 1

Status
Not open for further replies.

nberryman

Instructor
Jun 1, 2002
556
GB
I am using the following code to send an e mail to the recipient stored in the [EmailAddress] field.

Private Sub EmailAddress_DblClick(Cancel As Integer)

DoCmd.SendObject , , , Me![EmailAddress], , , "Subject goes here", "Message Text Here", True

End Sub

How do I attach a document whose name and path would be stored in a text box on the same form in Access 2000

Many thanks

Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
You can't with SendObject.
If you use Outlook (not Outlook Express), then it can be done like below:

Sub SendAttachedFile(FileNameAndPath$, AttachDescr$, ToAdds$, CCAdds$, BCCAdds$, SubjectLine$, MsgBody$)

Dim myOlApp, MyItem, MyAttachments
Set myOlApp = CreateObject("Outlook.Application")
Set myItem=myOlApp.CreateItem(olMailItem)

With myItem
.To = ToAdds
.CC = CCAdds
.BCC = BCCAdds
.Subject = SubjectLine
.Body = MsgBody
.Attachments.Add FileNameAndPath, olByValue, 1, AttachDescr
.Display 'this will display the result
.Send 'this will place the message immediately to Outbox
End With

set myItem = Nothing
MyOlApp.Close
Set myOlApp = Nothing
End Sub

All procedure arguments should be provided by text boxes on your form.
The procedure can be called from a command button:

Private YourButton_Click()
'whatever code you want to execute before sending the mail
Call SendAttachedFile(Me("FileTextBox"), Me("FileDescription"), Me("ToAddresses"), Me("CCAddresses"), Me("BCCAddresses"), Me("Subject"), Me("Body"))
End Sub

HTH
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Many thanks, I will try it out

Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top