• preventing end date being earlier than start date (2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » preventing end date being earlier than start date (2000)

    Author
    Topic
    #363597

    I have a form using the ActiveX calendar, two text boxes (start date and end date) with a button. If I click button and its caption reads “set start date” then the date I have selected on the calendar goes in the start date box and the caption changed to “set end date” – the code I am using is below (very basic as I am not very experienced in this yet!)

    Private Sub Button_Click()
    If button.Caption = “Set Start Date” Then
    TxtStartDate = calendar.Value
    button.Caption = “Set End Date”
    Else
    txtEndDate = calendar.Value
    button.Caption = “Set Start Date”
    End If
    End Sub

    What I am seeking is a bit of code to stop me adding an end date which is earlier than the start date – giving me an appropriate message and making me try again (naturally leaving the button saying “Set End Date”.

    Can anybody help please? I have tried putting validation rules in the properties of the text boxes themselves, but this has had no effect – so I guess it will have to be in the code?

    Thanks

    Roberta

    Viewing 1 reply thread
    Author
    Replies
    • #555336

      Roberta: Try this, making necessary name changes to meet your specs.

      ‘ Check to see that ending date is later than beginning date

      If IsDate(BeginningDate) And IsDate(EndingDate) Then
      If EndingDate < BeginningDate Then
      MsgBox "The ending date must be later than the beginning date."
      SetDate.Caption = "Set Ending Date"
      SelectDate.SetFocus
      Exit Sub
      End If
      Else
      MsgBox " Please us a valid date for the" & vbCrLf & _
      "beginning date and ending date values"
      Exit Sub
      End If

      • #555436

        Thanks for this. It will tidy up my form nicely.

        Roberta

    • #555534

      Why not test the dates and swap them with a bit of code? Then the user doesn’t have to retype the dates.

    Viewing 1 reply thread
    Reply To: preventing end date being earlier than start date (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: