Can I Tweak Error Message?

P

painesvillekid

I have a form with a list box. If the user selects a
record from the list and clicks my "Edit" command button,
a data form will open showing fields for the selected
record, which the user can then edit. But if the user has
not selected a record and hits the "Edit" button, a
cryptic error message will appear, provided by Access.

One trick I have been using is to go to the code for the
command button, comment-out the canned "Err.Description"
and replace it with something like: MsgBox "You need to
select a record from the list." THis seems to work, but I
sense that there's probably some reason why I shouldn't
do this. Any thoughts? Is anything bad going to happen?
 
C

Cheryl Fischer

You can certainly tweak the error messages so that they are more meaningful
to your users in the way that you already are - it's a professional touch
that makes your application more user friendly. I cannot think of anything
bad that will result from this practice.
 
J

Jeff Conrad

Try this code:

Private Sub cmdEdit_Click()
On Error GoTo ErrorPoint

If Me.lstMyListBox.ItemsSelected.Count = 0 Then
' They didn't select something
' so inform them they need to choose
MsgBox "Please make a selection from the " _
& "list before continuing.", vbInformation, _
"Which Record?"
' Return focus to the listbox
Me.lstMyListBox.SetFocus
Else
' They selected something
' Do your other stuff here
End If

ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub

Just replace lstMyListBox with your list box name of
course.
 

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