Can you disable the debugger?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an error which brings up the debugger screen to end of debug. Is
there a way to stop this from happening.
 
Eliminate what's causing the error; or put in an error handler that traps
the error and does something with it, even if ignoring it.

See On Error statement in Help file for more info.
 
Maybe you can help? The problem is with a mask on a date field. If a person
mistypes something or doesn't put in a valid date and tries to go to the next
text box it says that it is the wrong date and then goes into the debugger.
How is this avoidable can you use the on error since it is not in a
subroutine. Any suggestions? Or how can I set up something to catch the error
before it goes into the debugger?
Thanks
 
Not knowing the details of your setup, you could use the BeforeUpdate event
of the textbox to validate that what was entered is a valid date; and if
not, cancel the event and tell the user to enter a valid date.
 
Ok that sounds like a good idea, it will check it to see if it is a valid
date before moving tot he next field right? The before update is in the
properties of the text box right? How do you check to see if it is a valid
date? Do you know of a little piece of code that would do this?
Thanks for being so patient
 
I have tried looking and found the Error Handling part but could not many any
sense of it of what to do and how to impliment it into my current situation.
Any suggestions
 
In general you could have something like this in the after update event for
the text box (named txtDate in this example):

Private Sub txtDate_AfterUpdate()

On Error GoTo Err_txtDate_AfterUpdate

Exit_txtDate_AfterUpdate:
Exit Sub

Err_txtDate_AfterUpdate:
msgbox "Error #: " & Err.Number & " " & Err.Description
Resume Exit_txtDate_AfterUpdate

End Sub

In the example, Err_txtDate_AfterUpdate: is a line label. GoTo sends the
code there in case of an error. The error message will give you an error
number (let's say 1234). Now change the above code with the following after
Err_txtDate_AfterUpdate:

If Err.Number = 1234 Then
msgbox "Incorrect date format", vbCritical, "Format Error"
Else: msgbox "Error #: " & Err.Number & " " & Err.Description
Resume Exit_imgCmdCal2nd_Click
End If

End Sub

By the way, check Visual Basic help rather than Access Help. It is often
more complete on this sort of thing.
 
That didn't seem to catch the error here is what I put in:
Private Sub BirthDate_AfterUpdate()

On Error GoTo Err_BrithDate_AfterUpdate

Exit_BirthDate_AfterUpdate:
Exit Sub

Err_BirthDate_AfterUpdate:

If Err.Number = 2279 Then
MsgBox "Incorrect date format", vbCritical, "Format Error"
Else: MsgBox "Error #: " & Err.Number & " " & Err.description
Resume Exit_imgCmdCal2nd_Click
End If

End Sub

Did I do something wrong? Do you have any other suggestions?
 
Make the Resume line BirthDate rather than the leftover control name in the
code I copied from one of my projects but did not fully modify. You have
determined for sure that it is error 2279 (perhpas by entering an incorrect
format on purpose)?
 
Yes this is the right error is say Run-time error 2279 then something about
an incorrect mask.

Also when it goes into the debugger it goes to this statement on the
Me.Refresh line

Private Sub Patient_Entry_Click()
Me.Refresh 'used to refresh screen so new study entry's come up on main
form.
Sex.SetFocus
End Sub

maybe that is what is messing everything up.
 
Hard to tell with the line breaks in the newsreader, but is that two separate
lines of code (it should be), and does the comment occupy just one line in
your code window? Also, your code probably needs to be Me.Sex.SetFocus,
assuming Sex is the name of a control on the form.
You could turn those lines into remarks with an apostrophe and try the code
again.
 
Yes that is just the problem with the newsreader. It is all on one line
commented correctly. I just can't me the debugger stop after a incorrect
date is input. Just to let you know maybe there is something wrong with the
mask. Here is what I have for the mask: 99/99/0000;0;*
 
If the table has date/time as the data type and the text box is formatted
mm/dd/yyyy then any legitimate date will show in the format you want. If the
user enters 1/28, however, Access will change it to 01/01/1928. On the other
hand, if the user enters 1/2 Access will assume the current year and change
it to 01/02/2005. 1/1/4 becomes 01/01/2004. An input mask for a date is
sort of redundant since you can establish a date format. If you must have
one then 00/00/00;;* is as good as anything, I suppose, along with the
mm/dd/yyyy format. A two-digit year will automatically resolve itself to a
four-digit year without generating unnecessary errors. I would leave out the
0 after the first semi-colon, as there is no need I can see to store literal
values.
In my experience most users prefer a format that allows them to enter the
minimum amount of information. You may want to reconsider requiring eight
keystrokes for 02/05/2005 when 2/5 will accomplish the same thing.
Having said all that, the user applying an incorrect format generates an
error, but your error handling code is apparently incorrect. It is not the
error itself that opens the debugger but rather the procedure the code is
attempting to follow. It never gets a chance to run through all of the
instructions before it encounters some VBA no-no. It could just be some
simple formatting. Why don't you post the full AfterUpdate code? This
shouldn't be as complicated as it has become.
 
Yes this should have been this complicate. You know why because I put in
that stupid mask. I took it out completely (I thought that you had to put a
mask on the date) and it works find now. No debugger if something goes wrong
but a message comes up which I can live with. Thanks you for your patients
with me. It all worked out in the end and that is all that matters.
Thanks again for the help.
Eric
 
Glad it worked out. You can still use the code from my first posting to
isolate the error message, and to have your own message box appear. Date
already has a format, which is why you don't need an input mask as you would
with a phone number or something of that sort.
 
Back
Top