Well I'm almost there. That worked to send just one record but it sends it as
a Table View. Is there anyway to just send it so it has the same look as the
Form?
:
If you are using the form, here would be some sample code:
Me.Filter = "Idfield=" & Me.IDcontrolname
Me.FilterOn = True
DoCmd.SendObject acSendForm, Me.Name _
, , "(e-mail address removed)", , , _
"test form output", "attached is one record", True
In other words, you filter the form for the record you are
on and that is what will be output.
To show all records, make a button with the following code:
Me.FilterOn = True
Me.Requery
If you are emailing an actual report object, you can use
this code in a general module to save the filter before you
Send it
'~~~~~~~~~~~~~~~~~~~~
'------------------------------------ SetReportFilter
Sub SetReportFilter( _
byVal pReportName As String, _
byVal pFilter As String)
'Save a filter to the specified report
'You can do this before you send a report
' in an email message
'You can use this to filter subreports
' instead of putting criteria in the recordset
' USEAGE:
' example: in code that processes reports
' for viewing, printing, or email
' SetReportFilter "MyReportname","someID=1000"
' SetReportFilter "MyAppointments", _
' "City='Denver' AND dt_appt=#9/18/05#"
' written by Crystal
' Strive4peace2006 at yahoo dot com
' PARAMETERS:
' pReportName is the name of your report
' pFilter is a valid filter string
On Error GoTo SetReportFilter_error
'---------- declare variables
Dim rpt As Report
'---------- open design view of report
'---------- and set the report object variable
DoCmd.OpenReport pReportName, acViewDesign
Set rpt = Reports(pReportName)
'---------- set report filter and turn it on
rpt.Filter = pFilter
rpt.FilterOn = IIf(Len(pFilter) > 0, True, False)
'---------- save the changed report
DoCmd.Save acReport, pReportName
Exit_proc:
on error resume next
'---------- save the changed report
DoCmd.Close acReport, pReportName
'---------- Release object variable
Set rpt = Nothing
Exit Sub
SetReportFilter_error:
Resume Next
msgbox Err.Description, , _
"ERROR " & Err.Number & " SetReportFilter"
'press F8 to step thru code and fix problem
'comment next line after debugged
Stop : Resume
'next line will be the one with the error
resume Exit_proc
End Sub
'~~~~~~~~~~~~~~~~~~~~
then, here is a general function to email a report
'======================================== Email
'SendObject
'[objecttype]
'[, objectname]
'[, outputformat]
'[, to]
'[, cc]
'[, bcc]
'[, subject]
'[, messagetext]
'[, editmessage]
'[, templatefile]
'~~~~~~~~~~~~~~~~~~~~
'------------------------------------ EMailReport
Sub EMailReport( _
pReportName As String, _
pEmailAddress As String, _
pFriendlyName As String, _
pBooEditMessage As Boolean, _
pWhoFrom As String)
'Email a report to someone
'and construct the subject and message
'SNAPSHOT or RTF Format (comment one out)
'example useage:
'on the command button code to process a report
' EMailReport "rptSonglist", _
"(e-mail address removed)", _
"Original Songs from an upcoming Star", _
false, "Susan Manager"
'PARAMETERS
'pReportName --> "rptSonglist"
'pEmailAddress --> "(e-mail address removed)"
'pFriendlyName --> "Original Songs from an upcoming Star"
'pBooEditMessage --> true to edit before mail is sent
' --> false to send automatically
'pWhoFrom --> "Susan Manager"
On Error GoTo EMailReport_error
On Error Resume Next
'--------------- RTF FORMAT
DoCmd.SendObject acSendReport, _
pReportName, acFormatRTF, pEmailAddress _
, , , pFriendlyName _
& Format(Now(), " ddd m-d-yy h:nn am/pm"), _
pFriendlyName & " is attached --- " _
& "Regards, " _
& pWhoFrom, pBooEditMessage
'-------------- SNAPSHOT FORMAT -- commented out
' DoCmd.SendObject acSendReport, pReportName, _
acFormatSNP, pEmailAddress _
, , , pFriendlyName _
& Format(Now(), " ddd m-d-yy h:nn am/pm"), _
pFriendlyName & " is attached --- " _
& "Regards, " & pWhoFrom, pBooEditMessage
Exit_proc:
Exit Sub
EMailReport_error:
msgbox Err.Description, , _
"ERROR " & Err.Number & " EMailReport"
'press F8 to find problem and fix
'-- comment out next line when code is done
Stop : Resume
Resume Exit_proc
End Sub
'~~~~~~~~~~~~~~~~~~~~
Warm Regards,
Crystal
Microsoft Access MVP 2006
remote programming and training
strive4peace2006 at yahoo.com
*
Have an awesome day
Hoopster wrote:
I am using a Form to imput data into a Table and for each Record I enter I
want to send an E-Mail of only that record. Is it possible? When I use
SendObject, I get all the Records being sent by E-Mail.