Change Email from OnClick to On Deactivate

B

Bob V

My Report is emailed from an On Click control, I am want to change it to On
Deactivate of my Report is this possible, here is my code from a control
Thanks if you can help me...................Bob

Private Sub SendMailButton_Click()

On Error GoTo ErrorHandler

Dim lngID As Long, strMail As String, strBodyMsg As String, _
blEditMail As Boolean, sndReport As String, strCompany As String
Dim msgPmt As String, msgBtns As Integer, msgTitle As String, msgResp As
Integer

Select Case Me.OpenArgs

Case "ownerStatement"

sndReport = "rptOwnerPaymentMethod"

'---- Define parameters -----
lngID = Nz(Me.cbOwnerName.Column(0), 0)
strMail = OwnerEmailAddress(lngID)
'----- body message

strBodyMsg = "Dear "
strBodyMsg = strBodyMsg & Nz(DLookup("[ClientTitle]",
"tblOwnerInfo", _
"[OwnerID]=" & lngID), " ") & " "
strBodyMsg = strBodyMsg & Nz(DLookup("[OwnerLastName]",
"tblOwnerInfo", _
"[OwnerID]=" & lngID), " Owner")
strBodyMsg = strBodyMsg & "," & Chr(10) & Chr(10) & Chr(13) _
& "Attached is your Statement for the period from " &
Format(Me.tbDateFrom, "d-mmm-yy") _
& " to " & Format(Me.tbDateTo, "d-mmm-yy") & "." _
& eMailSignature("Best Regards", True) & Chr(10) & Chr(10) _
& DownloadMessage("rtf")

msgTitle = "Mail Statement"
msgBtns = vbYesNoCancel + vbQuestion + vbApplicationModal
msgPmt = "Do you wish to edit the email? " & Chr(13) &
Chr(13) _
& "* Click YES to edit the email before sending " & Chr(13)
_
& "* Click No to sent without editing " & Chr(13) _
& "* Click CANCEL to abort "
msgResp = MsgBox(msgPmt, msgBtns, msgTitle)
If msgResp = vbCancel Then
Exit Sub
Else
blEditMail = IIf(msgResp = vbYes, True, False)
End If

DoCmd.SendObject acSendReport, sndReport, acFormatRTF, strMail,
, , "Your Statement", _
strBodyMsg, True


Case Else
Exit Sub

End Select
Exit Sub

ErrorHandler:

msgTitle = "Untrapped Error"
msgBtns = vbExclamation
If Err.Number = 2501 Then 'Prevent error when send is canceled
Err.Clear
Exit Sub
End If
MsgBox "Error Number: " & Err.Number & Chr(13) _
& "Description: " & Err.Description & Chr(13) & Chr(13) _
& "(frmBillStatement SendMailButton_Click)", msgBtns, msgTitle


End Sub
 

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