Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default TEXTBOX - VALIDATE DATE INPUT

I want to ensure that an input to a textbox in a userform is in date format
either dd/mm/yy or dd mmm yy. Can anyone help ?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default TEXTBOX - VALIDATE DATE INPUT

Try something like


Dim S As String
S = InputBox("Enter A Date")
If S = Format(S, "d/m/yy") Or S = Format(S, "d mmm yy") Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Steve_G" wrote in message
...
I want to ensure that an input to a textbox in a userform is in
date format
either dd/mm/yy or dd mmm yy. Can anyone help ?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default TEXTBOX - VALIDATE DATE INPUT

Chip, I believe Steve was looking to validate entry in a textbox not through
a prompt. So I went to work on it, and tested this with a textbox which had
18/5/05 in it (May 18, 2005 written in the format Steve desired). I used the
immediate window to test, and with these results:

1) ?Typename(textbox1.value) Ans: string (good - expected)
2) ?Format(textbox.Value, "d/m/yy") Ans: 5/5/18 (bad - not expected)
Excel converted the textbox value into the wrong date because the format
d/m/yy is not innate. Therefore Textbox1.value can never =
Format(textbox.Value, "d/m/yy").

Do you have time to comment?

Bill


"Chip Pearson" wrote in message
...
Try something like


Dim S As String
S = InputBox("Enter A Date")
If S = Format(S, "d/m/yy") Or S = Format(S, "d mmm yy") Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If




--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Steve_G" wrote in message
...
I want to ensure that an input to a textbox in a userform is in
date format
either dd/mm/yy or dd mmm yy. Can anyone help ?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default TEXTBOX - VALIDATE DATE INPUT

Steve

I use the BeforeUpdate event like this

Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

With Me.TextBox1
If IsDate(.Text) Then
.Text = Format(.Text, "dd mmm yy")
Me.Label1.Caption = ""
Else
Cancel = True
Me.Label1.Caption = "Date required"
End If
End With

End Sub

It allows the user to enter the date in any format they like, but changes it
to your format. If they don't enter a valid date, it doesn't let them leave
the textbox and displays a message in an adjacent label that the entry isn't
valid.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

Steve_G wrote:
I want to ensure that an input to a textbox in a userform is in date
format either dd/mm/yy or dd mmm yy. Can anyone help ?



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
Trying to validate input based upon values in two other cells JG Excel Discussion (Misc queries) 1 December 11th 09 05:49 PM
Restrict-Filter-Limit-Validate user input in Excel Dr. Thom Excel Discussion (Misc queries) 0 January 22nd 06 08:06 PM
Validate textbox entry Stuart[_21_] Excel Programming 2 May 13th 05 07:31 PM
How can I validate data input by macros? ewan72 Excel Programming 2 February 23rd 05 04:13 PM
Validate Textbox entry David Seebaran Excel Programming 3 April 18th 04 06:26 PM


All times are GMT +1. The time now is 01:23 PM.

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"