Time and Err13 Type Mismatch

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi, I have a textbox on a form that has the system time entered as a default value via the UserForm_Activate event...

txtTime.Text = Format(Time, "hhmmss")

Im allowing Users to overtype this with their own time but if they enter an incorrect time then runtime err 13 Type Mismatch appears.

Whats the easiest way of preventing incorrect times being entered into the textbox so I avoid the runtime error.

thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
On 2002-08-26 15:34, parry wrote:
Hi, I have a textbox on a form that has the system time entered as a default value via the UserForm_Activate event...

txtTime.Text = Format(Time, "hhmmss")

Im allowing Users to overtype this with their own time but if they enter an incorrect time then runtime err 13 Type Mismatch appears.

Whats the easiest way of preventing incorrect times being entered into the textbox so I avoid the runtime error.

thanks

Hi Parry, what code are you using now for the Textbox ?? to mask for Time input.
 
Upvote 0
Hi Ivan, thanks for the reply. I believe the trim statement I had on the Change event was causing these errors so I removed them. I used trim to prevent spaces being entered.

To validate the field I decided to first check the textlength property was 6 digits then done mid string checks on hh mm & ss separately (to check hr not > 24 etc).

Seems to be working OK now.

cheers
Parry
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top