In the following code the only real variable is strRecipient = Me.CarrierName. If the operator fails to select the CarrierName on the form, but clicks the cmdbtn to invoke this code, he gets the MSmsg “Invalid use of Null” warning. The problem is that there is no description of where the null entry is located, and this form has nearly fifty entries. I would like to create my own pop-up to alert to the error and to describe where the null entry is located (i.e. “You must first select a carrier”). I suspect it would go in the ErrHandler, but I’m not confident of that.
Private Sub cmdLoadConfirmEmail_Click()
On Error GoTo ErrHandler
‘Email confirm to assigned carrier
Dim strReportName As String
Dim strRecipient As String
Dim strSubject As String
Dim strMessage As String
Dim blnEditMail As Boolean
strReportName = “rptLoadConfirmSingleEmail”
strRecipient = Me.CarrierName
strSubject = “Load Confirm Attached for PRO# ” & Me.ProNo
strMessage = “Please reply to this message with LOAD CONFIRMED (or similar text) in the message body.” _
& vbCrLf & vbCrLf & “Thank You,” & vbCrLf & “Bryan”
blnEditMail = True
DoCmd.SendObject acSendReport, strReportName, acFormatSNP, strRecipient, , , strSubject, strMessage, blnEditMail
Exit Sub
ErrHandler:
If Err.Number = 2501 Then
‘E-mail cancelled – just ignore the error
Else
‘Other error – inform user
MsgBox Err.Description, vbExclamation
End If
End Sub