Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a text box in a userform. The box will be used to manually ente
a date, so I would like the "/" to appear between the month & day year as the date is entered as well as not allow invalid date entries. B -- Message posted from http://www.ExcelForum.com |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi BA,
There are several ways to do this. The best may be to use a specialized control instead of a TextBox...perhaps the Date/Time Picker. But you'll have to check licensing requirements and availability on client machines before using one. If you want to use a textbox, you could put some code behind it like this: Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) With TextBox1 If IsDate(.Text) Then .Text = Format$(.Text, "Short Date") Else .SelStart = 0 .SelLength = Len(.Text) MsgBox "Invalid date entered.", vbExclamation Cancel = True End If End With End Sub If you want the /'s to show up, then it would be somewhat trickier. Your best bet in that case may be to use 3 separate textboxes separated by labels with captions of "/". Then you could validate the concatenation of the textboxes assuming all three are filled in. If all three aren't filled in, you can raise an error when they attempt to proceed. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] barrfly wrote: I have a text box in a userform. The box will be used to manually enter a date, so I would like the "/" to appear between the month & day & year as the date is entered as well as not allow invalid date entries. BA --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
TextBox format? | Excel Discussion (Misc queries) | |||
TextBox format? | Excel Discussion (Misc queries) | |||
TextBox Format | Excel Discussion (Misc queries) | |||
Format Textbox as % | Excel Programming | |||
Format textbox for dates | Excel Programming |