I use this, cmdEMailReport-Click() is a command button on a form called
Frm_Customer
Hope this is some help.
Regards,
John A
Private Sub cmdEmailReport_Click()
On Error GoTo cmdEMailReport_Click_Err
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
Dim StrCriterion As String
'This forces the record to be saved.
If Me.Dirty Then
Me.Dirty = False
End If
' This checks to see if the form is blank, before it allows a preview print
etc.
If IsNull(Me!CustomerID) Or Me!CustomerID = "" Then
strMsg = "You cannot send a blank E-mail."
strTitle = "E-Mail Error"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Exit Sub
End If
'This will hide the Customer form
Me.Visible = False
StrCriterion = " [CustomerID]=" & Forms![Frm_Customer].[CustomerID]
DoCmd.OpenReport "Rpt_Customer", acPreview, , StrCriterion
'This will minimize the report, whilst the e-mail in being prepared, I have
tried not to have it open in preview but
'cannot get it to work.
DoCmd.Minimize
'This will create the e-mail
DoCmd.SendObject acReport, "Rpt_Customer", "RichTextFormat(*.rtf)", "", "",
, "Customer Report", "", False, ""
'This explains all the section of the e-mail see SendObject in help
Rem example from help DoCmd.SendObject [objecttype][, objectname][,
outputformat][, to][, cc][, bcc][, subject][, messagetext][, editmessage][,
templatefile]
'This will close the report when you either cancel or send the e-mail. The
Frm_Customer will open
DoCmd.Close acReport, "Rpt_Customer"
cmdEMailReport_Click_Exit:
Exit Sub
cmdEMailReport_Click_Err:
MsgBox Error$
Resume cmdEMailReport_Click_Exit
End Sub