Agil GA
Agil GA

Reputation: 35

How to limit DTPickers available date?

I have these 2 DTpickers in my visual basic form: Date Picker screenshot

After the user picks a date from the upper DTPicker, I want the second DTPicker below it to be limited in selection.

e.g If I picked a date from the upper DTPicker, let's say 12/07/2017, the one below it will be limited to 13/07/2017 and above it (limited to the day after the first DTPicker, and up). How can I achieve this?

Upvotes: 2

Views: 365

Answers (1)

Giorgio Brausi
Giorgio Brausi

Reputation: 414

Set the MinDate property of next DTPicker in according of the date selected in DTPicker1:

Private Sub DTPicker1_Change()
    DTPicker2.MinDate = DateAdd("d", 1, DTPicker1.Value)

    ' You can also automatically select the first day allowed
    DTPicker2.Value = DTPicker2.MinDate
End Sub

Upvotes: 4

Related Questions