Call a msgbox on a specific error

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?
 
W

Wayne Morgan

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
 
R

Rick Brandt

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
 
T

Tim Ferguson

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
 

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