Customise Error Message

N

Nick

I have the code below, which seems to work OK.
Is there any way I can customise the Error message that
may appear?

All help is appreciated
Nick

Private Sub Form_Load()
On Error GoTo Form_Load_Err

' Disables action queries
Call Init
' Deletes tbBacklog
DoCmd.OpenQuery "qyDelete_Table_Backlog", acNormal,
acEdit
' Imports Backlog.xls
DoCmd.TransferSpreadsheet acImport, 8, "tbBacklog",
DLookup("File_Location", "tbDefaults"), True, ""
' Appends work centres
DoCmd.OpenQuery "qyWorkCentres-Apend_tbWork Centre",
acNormal, acEdit
' Appends planner groups
DoCmd.OpenQuery "qyPlannerGroup-Apend_tbPlanner
Group", acNormal, acEdit

Form_Load_Exit:
DoCmd.Close
DoCmd.OpenForm "Switchboard"

Exit Sub

Form_Load_Err:
MsgBox Error$
Resume Form_Load_Exit

End Sub
 
G

Guest

Nick

If you add a variable at the beginning of the code (just above the On Error
Goto line)

dim lngErr as long

Then if you replace the two lines below the " Form_Load_Err:" line with:

lngErr = Err.Number

Select Case lngErr

Case 'expected error no'
(if you know of any specific errors that are likely to occur then
you may be able to write some code to handle this without notifying the
user if that is appropriate depending on the error) eg if you just wish to
ignore it and ignoring it will not matter then just a Resume Next may be OK.

(if the above is not appropriate for the given error, and you just
want to cancel Loading then):

MsgBox "Custom error message " & lngErr.Number & " Details: " &
lngErr.Description, vbOKOnly + vbExclamation, "Unanticipated Error"
Resume Form_Load_Exit

Case Else

MsgBox "Unanticipated Error etc. " & lngErr.Number & " Details: " &
lngErr.Description, vbOKOnly + vbExclamation, "Unanticipated Error"
Resume Form_Load_Exit

End Select

Hope this helps

Ross
 

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