Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Date format in textbox
I have a userform with a textbox that I wish to enter dates in. Currently excel treats the datatype as text
1) What can I do to force it to enter dates instead of text 2) And to force any date validation Regards Bruce |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Date format in textbox
Hi Bruce,
trap the values as entered Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) With TextBox1 If Not IsDate(.Text) Then MsgBox "Invalid date" .SelStart = 0 .SelLength = Len(.Text) .SetFocus Cancel = True End If End With End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 45 To 47 '/ - or . Exit Sub Case 48 To 57 'Nos 0 - 9 Exit Sub Case Else Application.EnableEvents = False KeyAscii = 0 Application.EnableEvents = True Beep End Select End Sub You could make it tighter by ensuring that only 2 chars are ebtered before a delimite, only two delimiters, same tyep, etc. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Bruce" wrote in message ... I have a userform with a textbox that I wish to enter dates in. Currently excel treats the datatype as text. 1) What can I do to force it to enter dates instead of text. 2) And to force any date validation. Regards, Bruce |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Date format textbox? | Excel Discussion (Misc queries) | |||
Date format of a textbox | Excel Discussion (Misc queries) | |||
Textbox date format. | Excel Discussion (Misc queries) | |||
Date format textbox | Excel Discussion (Misc queries) | |||
converting date from a textbox to a date format | Excel Programming |