textbox validation for date and condition

  • Thread starter tkraju via OfficeKB.com
  • Start date
T

tkraju via OfficeKB.com

How to validate a textbox entry(userform) for date entry and not be greater
than today's date.
 
H

Harald Staff

This is just as much a When question, you must do everything after entry is
done:

Private Sub CommandButton1_Click()
Dim DT As Date
On Error Resume Next
DT = DateValue(Me.TextBox1.Text)
Select Case DT
Case 0 To DateSerial(1910, 1, 1)
MsgBox "no good"
Me.TextBox1.Text = ""
Me.TextBox1.SetFocus
Case Date + 1 To Date + 1000000
MsgBox "no good"
Me.TextBox1.Text = ""
Me.TextBox1.SetFocus
Case Else
MsgBox DT
End Select
End Sub
 
T

tkraju via OfficeKB.com

thank you !!

Harald said:
This is just as much a When question, you must do everything after entry is
done:

Private Sub CommandButton1_Click()
Dim DT As Date
On Error Resume Next
DT = DateValue(Me.TextBox1.Text)
Select Case DT
Case 0 To DateSerial(1910, 1, 1)
MsgBox "no good"
Me.TextBox1.Text = ""
Me.TextBox1.SetFocus
Case Date + 1 To Date + 1000000
MsgBox "no good"
Me.TextBox1.Text = ""
Me.TextBox1.SetFocus
Case Else
MsgBox DT
End Select
End Sub
 

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.

Ask a Question

Top