If you respond in that way, you reduce your chances of getting assistance
If that had been directed to me, I wouldn't be offering any further assistance. However, on the presumption you might have decided to dial things back a bit, I'll suggest the following, which is geared towards using a sub to present a message box:
Code:
Private Sub ForWhateverThisIs
Dim strMsg As String
After declaring all variables (Dim this or that As whatever) put
On Error GoTo errHandler (call your line label what you like; I call it errHandler)
your code goes here
exitHere: a line label that may or may not be needed to direct flow to an exit point
- close any recordsets
- destroy any created objects to reclaim memory resources
Exit Sub (without this, code will enter the error handling block)
trapping the potential errors would require If statements/blocks or Select Case blocks to decide what to do.
For example, "Invalid use of Null" [error 94]) follows. The example also calls a sub to produce the message box,
which as previously stated, is optional. The message can be constructed anywhere any number of times.
errHandler:
Select Case Err.Number
Case n
strMsg = "Whatever #1"
errMessage strMsg (pass the message string to ErrMessage sub)
Case x
strMsg = "Whatever #2"
errMessage strMsg
Case 94
strMsg = "The required controls cannot be blank"
errMessage strMsg
End Select
Resume exitHere
if code should end (the case statements might Resume or Resume Next instead, if appropriate)
End Sub
Code:
Public Sub ErrMessage (str As String)
Msgbox str (+ any options you want to add to the message box)
End Sub
It would also be possible to a) pass multiple parameters to the sub, such as button options; b) make it a Function so that it could return the button clicked, such as Yes or No or Cancel.
One of the main points already made is that if your vbe options are to break on all errors, then you will expose users to the code unless the db is compiled (saved as accde). Also, when you have the editor open, you can expect code to appear regardless, but if not, and the option isn't Break on All Errors, then the code shouldn't be exposed to the users. If you have such concerns, be diligent about making backup copies.