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").
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.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.