Click to See Complete Forum and Search --> : Checking Date range
Sigal Laniado
January 10th, 2000, 02:09 AM
I want to make a small dialog box which contains
"From Date" and "To Date" input user fields .
I need to validate that the dates inserted by the user are correct.
Is there any code around that do somthing similar?
Lothar Haensler
January 10th, 2000, 02:23 AM
try the IsDate function. It returns False for invalid dates.
Dr_Michael
January 10th, 2000, 03:03 AM
I would do it with two date picker controls:
private Sub Form_Initialize()
'initialize controls
DTPicker1.Value = Now
DTPicker2.Value = Now
DTPicker1.MaxDate = Now
DTPicker2.MaxDate = Now
DTPicker2.MinDate = Now
End Sub
private Sub DTPicker1_Validate(Cancel as Boolean)
'set the earliest date for dtpicker2 equal to the selected date from dtpicker1
DTPicker2.MinDate = DTPicker1.Value
End Sub
You can retrieve the values entered with the value property of each dtpicker control. For any further questions, post them here! ;-)
Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece
Leo Koach
January 10th, 2000, 03:35 AM
Try this
Private Sub Command1_Click()
Dim Date1 As Date
Dim Date2 As Date
Date1 = Format(Text1, "dd/mm/yyyy")
Date2 = Format(Text2, "dd/mm/yyyy")
If Date1 - Date2 >= 0 Then
MsgBox "Please enter the correct dates"
End If
End Sub
It works for me.
Good luck.
Leo
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.