How do you force a user to enter the correct date while comparing 2 date fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stress999
    New Member
    • Oct 2014
    • 12

    How do you force a user to enter the correct date while comparing 2 date fields

    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.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    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:

    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
    Hope this hepps!

    Comment

    • stress999
      New Member
      • Oct 2014
      • 12

      #3
      Thx Twinnyfo, mission complete.

      Comment

      • twinnyfo
        Recognized Expert Moderator Specialist
        • Nov 2011
        • 3662

        #4
        Great to hear it! Glad we could be of service!

        Comment

        Working...