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???
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