#8069
Support 1
Participant

>if the user put the start and end date manually in the fields nothing happens…

I am not sure what you mean by “fields”. Are you referring to the DateTimePicker or Edit control? I suggest that you permit users to choose dates using only the DateTimePicker.

You can compare the Date properties of two DateTimePicker controls as shown in the example below:

'Datefunction Start
Sub PickerStartChange(Sender)
  dim fromDate
  dim toDate

  fromDate = TasoUrlaub.PickerStart.Date
  toDate = TasoUrlaub.PickerEnd.Date
  if toDate > fromDate then
    MsgBox "Start date cannot be later than End date."
  end if
End Sub

Your OnChange handler can also be used to fix an incorrect date after a user has broken the rule, as shown below:

'Datefunction Start
Sub PickerStartChange(Sender)
  dim fromDate
  dim toDate

  fromDate = TasoUrlaub.PickerStart.Date
  toDate = TasoUrlaub.PickerEnd.Date
  if toDate > fromDate then
    MsgBox "Start date cannot be later than End date."
    TasoUrlaub.PickerStart.Date = TasoUrlaub.PickerEnd.Date
  end if
End Sub

Another option is to use the OnUserInput event if you want to prevent a change to the date that breaks the rule. Note that you will need to edit the handler that is created automatically – add the ByRef keyword as shown below:

Sub PickerStartUserInput(Sender, UserString, DateAndTime, ByRef AllowChange)

  dim fromDate
  dim toDate

  fromDate = TasoUrlaub.PickerStart.Date
  toDate = TasoUrlaub.PickerEnd.Date
  if toDate > fromDate then
    AllowChange = false
  end if

End Sub

In addition, I suggest using the built-in VBScript named constants, eg. vbSaturday, vbSunday instead of “magic numbers” like 7, 1, etc.

I hope this helps.

Regards,
Advansys Support

[This message was edited by Support 1 on October 06, 2008 at 08:28 PM.]