Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
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
Date format textbox? Tdp Excel Discussion (Misc queries) 2 October 15th 08 08:11 PM
Date format of a textbox Tdp Excel Discussion (Misc queries) 7 October 14th 08 10:27 PM
Textbox date format. AOU Excel Discussion (Misc queries) 2 April 24th 07 02:28 PM
Date format textbox George Excel Discussion (Misc queries) 2 September 20th 06 09:09 PM
converting date from a textbox to a date format neowok[_17_] Excel Programming 5 February 23rd 04 01:40 PM


All times are GMT +1. The time now is 10:23 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"