How do you force a user to enter the correct dates (In & Out dates) while comparing 2 date fields in MS Access. User should get an error message indicating "Out date should be greater than In date.
How do you force a user to enter the correct date while comparing 2 date fields
Collapse
X
-
stress999,
Much like in your other thread, the general code will be the same. But, if you want to prevent the user from moving on, just add code that disables any controls that would allow them to move along.
Assuming that the user enters Date1, then enters Date2, then they click a "Search" button, for example, just disable the Search Button if the dates don't meet the criteria:
Hope this hepps!Code:Option Explicit Private Sub txtDate1_AfterUpdate() VerifyDates End Sub Private Sub txtDate2_AfterUpdate() VerifyDates End Sub Private Sub VerifyDates() If Not (IsNull(Me.txtDate1) Or IsNull(Me.txtDate2)) Then If Me.txtDate2 < Me.txtDate1 Then Me.txtWarning = "Date 2 must be after Date 1" Me.cmdSearch.Enabled = False Else Me.txtWarning = "" Me.cmdSearch.Enabled = True End If End If End Sub
Comment