Textbox validation
'With validtion for current month
Assuming the text boxes are named txtStartDate and txtEndDate..
Private Sub CommandButton1_Click()
If IsDate(txtStartDate) = False Or IsDate(txtEndDate) = False Then
MsgBox "Invalid Date range"
txtStartDate.SetFocus: Exit Sub
ElseIf CDate(txtEndDate) <= CDate(txtStartDate) Then
MsgBox "End Date should be greater then Start date"
txtEndDate.SetFocus: Exit Sub
ElseIf Format(CDate(txtStartDate), "mmyyyy") < _
Format(Date, "mmyyyy") Then
MsgBox "Date should be of current month"
txtStartDate.SetFocus: Exit Sub
ElseIf Format(CDate(txtEndDate), "mmyyyy") < _
Format(CDate(txtStartDate), "mmyyyy") Then
MsgBox "Both dates should be of the same month"
txtEndDate.SetFocus: Exit Sub
End If
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria
"Jacob Skaria" wrote:
Assuming the textboxes are named txtStartDate and txtEndDate and you need
this validation to happen at CommandButton1 click
Private Sub CommandButton1_Click()
If IsDate(txtStartDate) = False Or IsDate(txtEndDate) = False Then
MsgBox "Invalid Date range"
txtStartDate.SetFocus: Exit Sub
ElseIf CDate(txtEndDate) <= CDate(txtStartDate) Then
MsgBox "End Date should be greater then Start date"
txtEndDate.SetFocus: Exit Sub
ElseIf Format(CDate(txtEndDate), "mmyyyy") < _
Format(CDate(txtStartDate), "mmyyyy") Then
MsgBox "Both dates should be of the same month"
txtEndDate.SetFocus: Exit Sub
End If
End Sub
If this post helps click Yes
---------------
Jacob Skaria
"TUNGANA KURMA RAJU" wrote:
how to Validate a TextBox entry with 3 conditions in Userform?
Textbox2 entry must be a date,that date must be of current month & current
year and it should be greater than TextBox1 date.
|