Function to validate a Start and End date

*****Function to validate a Start and End date *****

 

This function is to make sure the information entered on these fields is a Date format and also to ensure the Ending Date is greater than or equal to the Starting Date. You should have two text boxes or two fields with a data type as Date/Time for the Start Date and End Date. Name two fields as

StartDate for the Starting Date
EndDate for the Ending Date

call this function on the After Update Event of the EndDate as

Private Sub EndDate_AfterUpdate()
     Call IsValidDate
End Sub
Private Function IsValidDate(StartDate as Date, EndDate as Date) As Boolean
 Dim strMsg As String
 
 If IsDate(StartDate) = True And IsDate(EndDate) = True Then
    If StartDate > EndDate Then
        strMsg = "Start Date must be EQUAL TO or LESS THAN End Date."
    End If
 Else
    strMsg = "Both the Start Date and End Date are required."
 End If
 
 If Len(strMsg) = 0 Then
     IsValidDate = True
 Else
    MsgBox strMsg, vbOKOnly, "Date Entry Error" 'Windows Message Box
    IsValidDate = False
 End If
End Function
Prostate-Specific Antigen (PSA) (Men Only) High levels of uric acid restrict blood flow to the reproductive organs. levitra 40 mg https://www.unica-web.com/archive/1999/1999.html The medicine provides long lasting erection that remains active for a brief period of around 4 to 6 hours. levitra sales cialis 5mg sale Being extremely effective health, the medicine allows men engaging into an intercourse activity and develops healthy erections as well. The Benefits of Treating Erectile Dysfunction Treating erectile dysfunction and other sexual problems is a path breaking solution to all prostate gland related urological problems, viagra brand online Sagar Hospitals brings to Bangalore the world’s most advanced, breakthrough, out-patient Laser procedure for the treatment of Benign Prostatic Hyperplasia (BPH) and Propecia for the treatment of male pattern baldness. How to Use

When we have two textboxes with a date format on form;

StartDate for the Starting Date
EndDate for the Ending Date

we can test it with the If Statement before process the code if it is valid date entry for both the the End date must be greater than the Start date.

If IsValidDate(Me.StartDate, Me.EndDate) = True Then
  ‘process task
End If

 



Related posts