Emailing Current Record

J

Jorge Ramos

Hello all,



I have a form that must be sent by email to a predetermined person once it
is completed. It is important, however, that only the current record be
sent. Is there a way to automate this by creating a Command Button? The
Access Wizard creates the following code to allow you to print the form
showing the current record. However, the Wizard it does not offer an option
to email the current record.





Private Sub Print_Current_Record_Click()

On Error GoTo Err_Print_Current_Record_Click





DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

DoCmd.PrintOut acSelection



Exit_Print_Current_Record_Click:

Exit Sub



Err_Print_Current_Record_Click:

MsgBox Err.Description

Resume Exit_Print_Current_Record_Click



End Sub





Separately, the Access Wizard allows you to print a report. However, the
report contains all the records on the table or query and not just the
current record.



Any ideas as to how I can do this?
 
D

Daniel Pineault

The proper approach is to build a report based on the form data source and
then simply e-mail the report (with a where condition to limit it to the
current record) by using the sendobject method.

Or

you could use automation and manually pass each value to the e-mail body,
somthing like

Dim strToWhom As String
Dim strMsgBody As String
Dim strSubject As String

strSubject = "Your Subject goes here!"
strTo = "(e-mail address removed)"
strBody = "Your Body text goes here! Your Form values would go here ..." &
Me.Control01Name & vbCrlf & Me.Control02Name & vbCrlf & Me.Control03Name &
"..."

DoCmd.SendObject , , , strTo, , , strSubject, strBody, True
 
T

Tony Toews [MVP]

Daniel Pineault said:
The proper approach is to build a report based on the form data source and
then simply e-mail the report (with a where condition to limit it to the
current record) by using the sendobject method.

That won't work.

For a page on how to print a report for a single record and how to
generate reports to attach to emails see the Emailing reports as
attachments from Microsoft Access page at
http://www.granite.ab.ca/access/email/reportsasattachments.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
D

Daniel Pineault

That's an odd thing to say. I've done it in the past and it works fine. set
up the report to pull the ID from the active form and e-mail it.
--
Daniel Pineault
 
T

Tony Toews [MVP]

Daniel Pineault said:
That's an odd thing to say. I've done it in the past and it works fine. set
up the report to pull the ID from the active form and e-mail it.

How do you pull the ID from the active form? That's the key. Where
clause won't work. Hmm, although maybe it will for SendObject. I
don't know that I've ever used it.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
J

Jorge Ramos

Thanks to Tony and Daniel for your excellent and timely suggestions and
advice.



I placed the following code on the On Click event of my form:



Private Sub Email_This_Record_Click()

On Error GoTo Err_Email_This_Record_Click



Dim stDocName As String

stDocName = "Rate Locks - Current Record"

DoCmd.SendObject acReport, stDocName, "SnapshotFormat(*.snp)", "", "",
"", "Your Rate Lock Report", "Enter your preferred text here. This will be
the text of your email.", True, ""



Exit_Email_This_Record_Click:

Exit Sub



Err_Email_This_Record_Click:

MsgBox Err.Description

Resume Exit_Email_This_Record_Click

End Sub





In addition, I placed the following on the On Open event of my Report to
limit it to the current record on the Form:



Private Sub Report_Open(Cancel As Integer)

Me.Filter = "ID=" & Forms![Rate Locks Data Entry Form]![ID]

Me.FilterOn = True

End Sub





Everything works great! Thank you once again!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top