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 from within form 1

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
0
0
GB
I am trying to include a button that sends an email with the contents of certain fields included in the message body. I can manage to do this using a report, but want to just send a plain text email. Any suggestions please.

Craig
 
Hi, this is how I did it:
----------------------------------------------
Dim emailto As String
Dim messagetext As String
Dim subjecttext As String

emailto= Me!emailfield

messagetext = "Customer: " & customername & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
"Contact: " & contactname & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
"Contact Tel: " & contactnumber & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
"Contact Email: " & contactemail & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
"Subject: " & Subject & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
"Related Contract: " & Text41 & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
"Details: " & Chr(13) & Chr(10) & Details & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _
Chr(13) & Chr(10)

subjecttext = "You have a query from " & customername & "."

DoCmd.SendObject , , , emailto, , , subjecttext, messagetext, False
------------------------------------------------------------
To pull it apart:
messagetext = "Customer: " & customername & Chr(13) & Chr(10) & Chr(13) & Chr(10) & _

This builds up the body of the email as a string called "messagetext".
customername referred to above is the name of the text field on the form which contains the customer's name. and so on. The Chr(x) bits are for formatting (new lines).
The bit that sends the email is the docmd.sendobject command which sends it to the email address stored in the value field on the referring form.

Hope this helps.

 
Thanx Mate
That was a great help, I'd figured most of it but the Chr() bit for adding carriage returns was the "icing on the cake"
Thanks again

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top