Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Error Handling Problem

Greetings,

How do I set up an error handling routine that does not though me into
an endless loop?

I have a UserForm (UF1) with a TextBox (TB1), in which I need a date
entered into. When I exit TB1, I have the format changed to mmm dd,
yyyy. This works fine. the problem arises when the person entering
the data mistypes something in TB1 and it is NOT a legitimate date.
On exiting TB1, they get an error message telling them that they have
a type mismatch asking about debug. I have tried to use on error to
generate a msgbox and then unload the userform and then reload it, but
that just freezes my machine and I have to Control, Alt, Delete out of
Excel (we wont discuss lost data at this time).

So, the question is how do I set up an error handling routine? Is
there any info out there on the logic and design of error handling
routines? Any help would be appreciated.

TIA

-Minitman
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error Handling Problem

Without seeing the code and knowing where the error generates, it is
difficult to be sure, but could you not cast the text into a date, and if
the date is invalid it will error at that point which you can trap,
something like

On Error Resume Next
myDate = CDate(Textbox1.Text)
If myDate = 0 Then
MsgBox "Error"
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Minitman" wrote in message
...
Greetings,

How do I set up an error handling routine that does not though me into
an endless loop?

I have a UserForm (UF1) with a TextBox (TB1), in which I need a date
entered into. When I exit TB1, I have the format changed to mmm dd,
yyyy. This works fine. the problem arises when the person entering
the data mistypes something in TB1 and it is NOT a legitimate date.
On exiting TB1, they get an error message telling them that they have
a type mismatch asking about debug. I have tried to use on error to
generate a msgbox and then unload the userform and then reload it, but
that just freezes my machine and I have to Control, Alt, Delete out of
Excel (we wont discuss lost data at this time).

So, the question is how do I set up an error handling routine? Is
there any info out there on the logic and design of error handling
routines? Any help would be appreciated.

TIA

-Minitman



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Error Handling Problem

Hey Bob,

I guess I was to vague in my description. Then entry in TB1 is a date
which is formatted at exit to mmm dd, yyyy from mm/dd/yy. It is at
exit that an error will cause the problem.

The code in question looks like this:

Private Sub TB1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

'Deposit Date

TB1.Text = Format(DateValue(TB1.Text), "mmm dd, yyyy")
..
..
..
End Sub

As I said earlier, if the person entering the dates mangles the date
so that it is not a date, They get an error to press either "use
debug" or "OK". "OK" takes them out of the form and back to the
worksheet. Debug will also get you there, only longer.

Anybody have any ideas?

TIA

-Minitman



On Sun, 14 Nov 2004 20:10:07 -0000, "Bob Phillips"
wrote:

Without seeing the code and knowing where the error generates, it is
difficult to be sure, but could you not cast the text into a date, and if
the date is invalid it will error at that point which you can trap,
something like

On Error Resume Next
myDate = CDate(Textbox1.Text)
If myDate = 0 Then
MsgBox "Error"
End If


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error Handling Problem

That is what I guessed, so I would re-suggest my previous answer.

Private Sub TB1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

On Error Resume Next
myDate = CDate(TeB1.Text)
If myDate = 0 Then
MsgBox "Error"
Cancel = True
Else
TB1.Text = Format(DateValue(TB1.Text), "mmm dd, yyyy")
End If

I am not seeing why it causes a debug, but hopefully this would avoid it.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Minitman" wrote in message
...
Hey Bob,

I guess I was to vague in my description. Then entry in TB1 is a date
which is formatted at exit to mmm dd, yyyy from mm/dd/yy. It is at
exit that an error will cause the problem.

The code in question looks like this:

Private Sub TB1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

'Deposit Date

TB1.Text = Format(DateValue(TB1.Text), "mmm dd, yyyy")
.
.
.
End Sub

As I said earlier, if the person entering the dates mangles the date
so that it is not a date, They get an error to press either "use
debug" or "OK". "OK" takes them out of the form and back to the
worksheet. Debug will also get you there, only longer.

Anybody have any ideas?

TIA

-Minitman



On Sun, 14 Nov 2004 20:10:07 -0000, "Bob Phillips"
wrote:

Without seeing the code and knowing where the error generates, it is
difficult to be sure, but could you not cast the text into a date, and

if
the date is invalid it will error at that point which you can trap,
something like

On Error Resume Next
myDate = CDate(Textbox1.Text)
If myDate = 0 Then
MsgBox "Error"
End If




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error handling problem Jim G Excel Discussion (Misc queries) 2 October 3rd 07 02:19 AM
Handling #NUM! error Michel Khennafi Excel Worksheet Functions 1 February 26th 07 08:49 PM
Error Handling James Agostinho Excel Programming 1 January 30th 04 06:40 AM
Excel VBA - Error handling problem brutalmetal[_2_] Excel Programming 2 January 21st 04 03:17 AM
Error handling Tim C Excel Programming 1 October 7th 03 10:00 PM


All times are GMT +1. The time now is 07:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"