LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
Rob
 
Posts: n/a
Default Restrict date format for UserForm

I was given the following code some time ago (with some amendments by me),
to restrict the entry in a UserForm. I find that I can enter a date like
31/11/05 (which is not a correct date) but it is still excepted by the code,
(except that it transposes is to 5/11/31).

I would like, if possible, to only allow correct dates to be entered, and
then only in the d/m/yy format.
Can someone please reconstruct to achieve this?

Rob

Private Sub TextName1_KeyPress(ByVal _
KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub

Private Sub TextName1_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If Shift = 2 Then KeyCode = 0
End Sub
Private Sub CancelButton_Click()
Unload Me
End Sub

Private Sub OKButton_Click()
Dim D As Date
'Make sure a date is entered
If IsDate(TextName2.Text) Then
D = DateValue(TextName2.Text)
Else
MsgBox "You must enter a date."
'to clear wrong entry and reset form
Unload Me
EnterDate.Show
Exit Sub
End If
'Transfer the date
Range("G1") = D
Unload Me
End Sub


 
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
Change general format to US date format woodlot4 Excel Discussion (Misc queries) 3 October 11th 05 12:29 AM
Customized Date Format Frustrated Excel Worksheet Functions 5 October 7th 05 11:30 PM
date format in excel not in line with control panel regional setti GrahamR Excel Discussion (Misc queries) 3 August 2nd 05 06:48 PM
Compare dates (one cell not in date format) craigcsb Excel Discussion (Misc queries) 5 June 28th 05 05:07 PM
How do I keep the date from changing format in a mail merge? Brynn Wilson Excel Discussion (Misc queries) 1 June 9th 05 06:44 PM


All times are GMT +1. The time now is 07:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"