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!

E-Mail from a form

Status
Not open for further replies.

mike1975

IS-IT--Management
Jun 26, 2001
38
0
0
GB
Help,

Is there a way of e-mailing an individual record that is currently being displayed on a form?

Mike
 
Hey mike,

There is a way to do it but it takes a little bit of code and Outlook. The trick is, on the click event of the email button you have to declare a new outlook application, then attach the report of the form you're using to the email message. The "FindX" variable should be set equal to the number of the record that you're wanting to email. To do this, set FindX = to record_number. The only variable names you should have to change in this code is record_number and report_name. Note* you must have Outlook open to have this procedure work.

DoCmd.RunCommand acCmdRefresh
Dim pstrEmailName As String
Dim pstrComment As String
Dim pstrccName As String
Dim FindX
Dim strFileName As String
Dim strErrMsg As String
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim strWhere As String
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olMail = olApp.CreateItem(olMailItem)
FindX = record_number
strFileName = a file location to send the email
strWhere = "record_number=" & FindX
DoCmd.OpenReport "report_name", acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, "report_name", acFormatRTF, strFileName, False
DoCmd.Close

pstrEmailName = InputBox("Please enter your email destination", "Email")
pstrccName = InputBox("Enter CC address", "CC")
pstrComment = InputBox("Enter comments for your email", "Comments")
With olMail
.To = pstrEmailName
.CC = pstrccName
.Subject = "Incident Report #" & Case__
.Body = pstrComment
.Attachments.Add strFileName
.ReadReceiptRequested = False
.Send
End With
Kill strFileName
MsgBox "Request has been E-Mailed"

Hope it works out for ya.
-Darin g.
 
Thanks for the reply - I am using the code suggested however it does not seem to like this line,

Dim olApp As New Outlook.Application

any suggestions?

Mike
 
I have an alternate solution. Why not simply save your form as a report. Filter the report to be executed only for the current form record (Normally do this with a [forms]![forname]![fieldname] criteria) and then add a command button to your form which does a sendobject macro. The sendobject will open your email and execute your report at same time.
 
You need to add the outlook reference library to your database. That should fix the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top