Textbox Date Validation

proctk

Well-known Member
Joined
Dec 24, 2004
Messages
840
I need some code to validate how the date is entered in textbox on a userform.

Date formate must be dd-mmm-yy
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
protck

Why not just check a valid date has been entered and convert it required format?

I'm sure you could write code to check the format but I personally wouldn't do things that way.

For one thing you are restricting the user.
 
Upvote 0
Hello Kevin,
Something like this should get you started.
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox1.Text) Then
    TextBox1.Value = ""
    Ln1 = "There was as error in the date entry." & vbNewLine
    Ln2 = "Please enter a valid date."
    Style = vbOKOnly
    Title = "Date entry error"
    MsgBox Ln1 & Ln2, Style, Title
  Else: TextBox1.Text = Format(TextBox1.Text, "dd-mmm-yy")
End If
End Sub
Hope it helps.

[EDIT:]
Pretty much what Norie is suggesting I guess.
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,150
Members
448,552
Latest member
WORKINGWITHNOLEADER

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top