If you have a secured database and you have a user set up to only be able to read existing records and they attempt to add a new record (by clicking on a command button set up for this), you generally get a cryptic "You can't Go to the Specified Record" message. To set it up so that a customized error message comes up instead, use the following code:
Private Sub Command161_Click() On Error GoTo Err_Command18_Click DoCmd.Close acForm, "search_form" DoCmd.OpenForm "tool_build_request_form", acNormal, "", "", acAdd, acNormal DoCmd.GoToControl "stdate" Exit_Command18_Click: Exit Sub Err_Command18_Click: MsgBox "From Larry: You Don't have ADD RECORD permissions, you have READ ONLY level of permission." 'MsgBox Err.description Resume Exit_Command18_Click End Sub |
Notice the DoCmd.GoToControl "stdate" statement. Such a statement (you would substitute the correct field in the place of "stdate") is necessary to trigger the error (and hence the customized message).
Also, of course, this assumes there are no other errors with your command button which have to be resolved.
To instead have this error-trapping routine print the Access error message, yet make it clear to the user who to report the user to (and prevent the "Debug...End" box), enter the following:
MsgBox Err.description, _ vbCritical, "Error Message--Report this to Larry Harrison Jr" |