How to email the current record on a form

D

Dummy

Please forgive me if this is not the correct newsgroup.

I have a text box in a form for email addresses. I'd like to be able to
double-click an address so that the current record would be sent to the
"addressee" as an email attachment. If this is not possible, would it be
possible to add a command button to the form to obtain the same effect.

I know how to add to the form a Print command button that sends the current
record to the printer. I also know how to send to the printer specific field
contents on the current record. I looked at the code behind the Print
button, and I thought that the procedure could be amended to send the
current record to Outlook Express. But my VB knowledge is very poor.

Thanks for your help.
 
A

Allen Browne

SendObject can email the report to the user, but it does not have a
WhereCondition like OpenReport. That means you have to find another way to
pass the filter to the report.

A public variable can do that. You create it in a standard module, set it in
the command button that sends the report, and apply and reset it in the Open
event of the report.

1. Click the Modules tab of the Database window, and click New
Access opens a new module.
At the top, on a separate line just below the Option statements, enter:
Public gstrReportFilter As String
Save the module with a name such as Module1.

2. Open the report in design view.
Open the Properties box (View menu.)
Make sure the title bar of the Properties box says "Report" so you are
looking at the properites of the report (not a text box.)
On the Event tab, set the On Open property to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.
Add these 5 lines to the event procedure:

Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub

3. Add this code the the Click event procedure of the command button on your
form:

Private Sub cmdSend_Click()
If Me.Dirty Then
Me.Dirty = False
End If
If Not IsNull(Me.[ID]) Then
gstrReportFilter = "[ID] = "& Me.[ID]
DoCmd.SendObject acSendReport, "Report1",, Me.Email,,, _
"Here tis", "Find your report attached", True
End If
End Sub

Replace "[ID]" with the name of your primary key field.
Replace "Report1" with the name of your report.
 

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