Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Cheltenham, Gloucestershire, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    preventing end date being earlier than start date (2000)

    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

  2. #2
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Columbus, Ohio, USA
    Posts
    286
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: preventing end date being earlier than start date (2000)

    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

  3. #3
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Cheltenham, Gloucestershire, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: preventing end date being earlier than start date (2000)

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

    Roberta

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Altnau, Thurgau, Switzerland
    Posts
    447
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: preventing end date being earlier than start date (2000)

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •