I am using DoCmd.SendObject vba to email a report. I am using a dlookup to preset who the email should be sent to. However, sometimes the dlookup field may be blank. This causes the sendobject vba to error out. Any suggestions on how to get around this? Is there a way to just ignore the dlookup function if the field is empty. Below is the full sendobject code.
Code:
Private Sub btnEmailReport_Click()
On Error GoTo btnEmailReport_Click_Err
Dim ReportName As String
Dim Subject As String
Dim ToRecipient As String
Dim CCRecipient As String
Dim BCCRecipient As String
Dim Message As String
ReportName = "rptEmailReport"
Subject = "Report"
ToRecipient = ""
CCRecipient = DLookup("ManagerEmail", "tblContacts", "Location='" & Me.Location & "'")
BCCRecipient = ""
Message = "Hello"
DoCmd.RunCommand acCmdRefresh
DoCmd.SendObject acReport, ReportName, "PDFFormat(*.pdf)", ToRecipient, CCRecipient, BCCRecipient, Subject, Message, True, ""
btnEmailReport_Click_Exit:
Exit Sub
btnEmailReport_Click_Err:
MsgBox "Error #" & Err.Number & " - " & Err.Description, , "RMIS Error"
Resume btnEmailReport_Click_Exit
End Sub