Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation of textboxes in a userform

Status
Not open for further replies.

advox1

Technical User
Nov 28, 2003
26
0
0
GB
Hi I have two problems

1. In the first textbox of a userform I need a date to be entered. the format of this date has to be dd/mm/yy. How do I stop anyone from entering dates in any other format i.e. dd.mm.yy etc?

I had tried using a Combobox and validating the cells from a list in the spreadsheet, but when the selected date was chosen it changed it into numbers i.e. 16/02/04 became 30245 or something like this. Although when the info was dumped into the spreadsheet it reverted back, I don't want this to happen as it would confuse the user.

2. In two other textboxes I require times to be input a start time and a finish time which have to be entered as ##:## so that when the data is dumped into the spreadsheet I am using the formula to calculate the total time works.

Can anyone help me with the code to validate these boxes so that a message appears if the format is entered wrong and the data is deleted?

Thanks

Jo
 
You might try using the Format function in the AfterUpdate Event of each text box. For example:

txtbox1=Format(txtbox1.value, "dd/mm/yy")

Times are a little tricky since the user must enter a colon and an AM/PM (a or p works too).

The Format function should help you there too.



DreamerZ
simplesolutions@prodigy.net
[ignore][/ignore]
 
I don't know if I have this option because I do development in VB but...

If you look under the tools menu and select the additional controls option a popup dialog will appear.

Scroll down to the Microsoft Masked Edit Control and select the checkbox to the left of it. A new control should appear on the toolbox that looks like ##|. It works just like a text box except that you can control the input with the mask property. If you don't see it in the Additional Controls Dialog search your drive for the msmask32.ocx file. If you find it, put a copy in the system32 folder and then add a reference to it under the tools menu.

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top