Instead of two buttons you can prompt the user if to display the report in print preview or email it:
Code:
'ask if to email
On Error Resume Next
If MsgBox("Do you want to email this report as a PDF attachment?", vbYesNo, "Email report?") = vbNo Then
DoCmd.OpenReport "rptCurrentRecord_Email", acViewPreview ', "[ID]= " & Me.ID 'updated recordsource to only include the current record
Else
'DoCmd.SendObject acSendReport, "rptCurrentRecord_Email", acFormatPDF, "", , , "Your subject here" 'without saving the report as PDF
Dim sFileName As String,sEmail as string
'sFileName=.......'set your file name here
sEmail=Left([EmailAddress],Instr([EmailAddress],"#")) 'name@email.com#mailto:name@email.com#
DoCmd.OpenReport "rptCurrentRecord_Email", acViewPreview, , , acHidden
DoCmd.OutputTo acOutputReport, , "PDF Format (*.pdf)", sFileName
vcSendEmail_Outlook_With_Attachment ("Your subject",sEmail,,sFileName,"Your email body here")
End if
Function vcSendEmail_Outlook_With_Attachment(sSubject As String, sTo As String, Optional sCC As String, Optional sBcc As String, Optional sAttachment As String, Optional sBody As String)
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
OutMail.To = sTo
If sCC <> "" Then OutMail.CC = sCC
If sBcc <> "" Then OutMail.BCC = sBcc
OutMail.Subject = sSubject
If sBody <> "" Then OutMail.HTMLBody = sBody 'pr20111227
' Debug.Print sAttachment
' Stop
OutMail.Attachments.Add (sAttachment)
OutMail.Display 'Send | Display
' OutMail.Inspector.Activate
Set OutMail = Nothing
Set OutApp = Nothing
End Function
For your second question please try sEmail=Left([EmailAddress],Instr([EmailAddress],"#")) 'name@email.com#mailto:name@email.com#
Cheers,