Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Date Validation

I have a text box on my userform. What code do i need to add to the add
button so that it will check that it is a date (dd/mm/yyyy).
Thanks.
--
Cheers,
Ben

Remove your.tonsils to reply
"You only live once but if you do it right once is enough!"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Date Validation

Hi Ben,

Something like this may work for you:

With TextBox1
If Not IsDate(.Text) Then
MsgBox "Invalid date"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End If
End With

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Ben Allen wrote:
I have a text box on my userform. What code do i need to add to the
add button so that it will check that it is a date (dd/mm/yyyy).
Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Date Validation

Ben,

You can also trap the values as they are 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

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jake Marx" wrote in message
...
Hi Ben,

Something like this may work for you:

With TextBox1
If Not IsDate(.Text) Then
MsgBox "Invalid date"
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End If
End With

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Ben Allen wrote:
I have a text box on my userform. What code do i need to add to the
add button so that it will check that it is a date (dd/mm/yyyy).
Thanks.



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
Validation Date housinglad Excel Discussion (Misc queries) 4 February 8th 10 09:40 PM
DATE VALIDATION William Excel Discussion (Misc queries) 4 August 7th 08 02:31 PM
Date Validation - Must equal Sundays date jeridbohmann Excel Discussion (Misc queries) 14 November 30th 05 08:40 PM
Date Validation Nigel[_5_] Excel Programming 5 October 30th 03 05:09 PM
date validation Jo[_4_] Excel Programming 1 October 20th 03 08:50 PM


All times are GMT +1. The time now is 04:53 AM.

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"