Error handling A 2013

Dick7Access

Dick S
Local time
Today, 17:11
Joined
Jun 9, 2009
Messages
4,340
Is it necessary or recommended to code command buttons with error handlers?
 
In my world it is required!

To answer your question, I would say it would be recommended but not necessary. Of course, without it... well, we all know wht happens without it, especially if you deleiver a Runtime.
 
Up until this point I have always just copied error handling from somebody else’s code. I now want to fully understand the process and code my own error handlers. I am having a little trouble understanding the three different error handlers that are available. The tutorials that I goggled are not clear to me. Anybody have a link to an easy to understand tutorial.
 
Trying to study error handling I entered a record with no last name to evoke an error. Since the query sorts on the last name when I click the cmdOpenYourCh it will open the form based on the query and the record with no last name will be at the top of the list. When I click the cmd for next record or previous record my message box will say Already at last or previous.
I then entered this code to try and trap it. It doesn’t. What am I doing wrong?
Code:
  Private Sub cmdOpenYourCh_Click()
  On Error GoTo Proc_Err
  DoCmd.OpenForm "frmMain"
  DoCmd.ApplyFilter "qryOpenYourCh"
  Proc_Exit:
     On Error Resume Next
     Exit Sub
  Proc_Err:
     MsgBox Err.Description, , _
       "ERROR " & Err.Number _
       & "   cmdOpenYourCh"   
     Resume Proc_Exit
     Resume   
  End Sub
 
That will only envoke an error message if the Form or the Query is unavailable which is not the case. Having no last name has to do with the query and it can still Filter so I would expect there would be no error.

Are you trying to trap the *Next Record* message or the fact that there is no Last Name, which would not error be an error but more like validation which should have been handled when the name was entered.
 
That will only envoke an error message if the Form or the Query is unavailable which is not the case. Having no last name has to do with the query and it can still Filter so I would expect there would be no error.

Are you trying to trap the *Next Record* message or the fact that there is no Last Name, which would not error be an error but more like validation which should have been handled when the name was entered.

I am trying to learn proper error handling. The error (no last name) was intended to cause an error. Before I distribute the db I want to make sure something like the end user putting in all the other info and thinking they can put in the last name later, and have the app crash. Once I have that straighten out I will put in other errors to learn. As I said up until now I just used other peoples error handling code.
 
Oh, and I was just about to brag how good Crystal is at explaining stuff.! :eek:

Okay, let's see how good I am...

Error handling does not validate data entry. That is handled during data entry. Error handling handles errors in evaluating your code. So, if you code says say... Delete a record but it can't because it's *attached* to another record in another table and cascading deletes is not checked your code will throw up an error... well, you can use code to *trap* it and give the User a *real* error message OR shut the error up and not it show.

BUT if you want to validate that a Last Name has been entered AND since it's not a primary key you need to do that at the Form level. No error code is going to care if particular fields are filled out unless they happen to be a PK AND interfere with it's *job*.

Does that help? :)
 

Users who are viewing this thread

Back
Top Bottom