Call a msgbox on a specific error

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

If a certain value is null (which will call an error in my
code), I want to call a msgbox stating "You can't have a
null value blah, blah". I know what the error is, because
it pops up. Is there a way to call a msgbox on this error
only, and still have Access pop up an error description if
it is any other error?
 
Yes, just use an If statement in your error handler code.

Example:

ErrorHandler:
If Err.Number = 2022 Then
Msgbox "Please Try Again"
Resume
End If
Msgbox "An Error occurred that wasn't expected"
'more code as you wish
 
Rick said:
If a certain value is null (which will call an error in my
code), I want to call a msgbox stating "You can't have a
null value blah, blah". I know what the error is, because
it pops up. Is there a way to call a msgbox on this error
only, and still have Access pop up an error description if
it is any other error?

Sub SomeSub

On Error GoTo ErrHandler

some code goes here

Egress:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 94 'Invalid use of Null
MsgBox "You can't have a null value blah, blah".
Case Else
MsgBox "Error " & Err.Number & vbcrlf & vbcrlf &
Err.Description
End Select
Resume Egress
End Sub
 
If a certain value is null (which will call an error in my
code), I want to call a msgbox stating "

if IsNull(varCertainValue) then
msgbox "That was null, you ninny!"
end if

Tim F
 
Back
Top