Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DTPicker ValueChanged Loop

Status
Not open for further replies.

oticonaus

Technical User
Dec 16, 2003
96
AU
I am sure there must be an easy way around this...

I have a DateTimePicker and when the user selects a date, I want to test the weekday of the date and if it is a Saturday or Sunday, then change the selected date to Monday.

But as soon as I change the date to Monday, it fires up a loop. How do I get around this???

Code:
Private Sub Date2_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Date2.ValueChanged
        If Weekday(Date2, FirstDayOfWeek.Saturday) Then
            Me.Date2.Value = DateAdd(DateInterval.Day, 2, Date2)
        ElseIf Weekday(Date2, FirstDayOfWeek.Sunday) Then
            Me.Date2.Value = DateAdd(DateInterval.Day, 1, Date2)
        End If
End Sub
 
I solved my own problem...

The code should have read

Code:
        If Weekday(Date2) = 7 Then
            Me.dtpLeaveTo.Value = DateAdd(DateInterval.Day, 2, Date2)
        ElseIf Weekday(Date2) = 1 Then
            Me.dtpLeaveTo.Value = DateAdd(DateInterval.Day, 1, Date2)
        End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top