This function is supposed to alert the user if there is an attempt to change the date to another date (other than Today). When the user clicks Yes in the Messagebox another message box pops up to let the user know that date is changed and the new date chosen is displayed on the datetimepicker box as soon as the user clicks OK.
Basically the code works but the small issue is in the If statement when the "response = MsgBoxResult.No". When the user clicks on "No" in the message box to indicate they want to keep today's date, after the first click of "No" the message box does not disappear unless you click on "No" again. when the message box indicating that appears "Keeping today's date...." you again have to click "OK" twice to make it disappear and then it shows the first message box again and you click "No" twice and then "OK" twice to return control to the main forms window.
This problem can be removed by commenting the "Datetimepicker1.value = datetime.today" line but the date does not default to Today and the datetimepicker box shows the date that was selected.
Here's the code:
' ****************************************************
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
Dim msg = "Do you want to Overwrite The Date"
Dim title = "Pick Another Date"
Dim style = MsgBoxStyle.YesNo
Dim response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
DateTimePicker1.Format = DateTimePickerFormat.Short
MsgBox("The Date Has Been Changed to " & _ DateTimePicker1.Value.ToShortDateString)
Exit Sub
End If
If response = MsgBoxResult.No Then
DateTimePicker1.Value = DateTime.Today
MsgBox("Keeping Today's Date " & Today.ToShortDateString)
Exit Sub
End If
End Sub
Basically the code works but the small issue is in the If statement when the "response = MsgBoxResult.No". When the user clicks on "No" in the message box to indicate they want to keep today's date, after the first click of "No" the message box does not disappear unless you click on "No" again. when the message box indicating that appears "Keeping today's date...." you again have to click "OK" twice to make it disappear and then it shows the first message box again and you click "No" twice and then "OK" twice to return control to the main forms window.
This problem can be removed by commenting the "Datetimepicker1.value = datetime.today" line but the date does not default to Today and the datetimepicker box shows the date that was selected.
Here's the code:
' ****************************************************
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
Dim msg = "Do you want to Overwrite The Date"
Dim title = "Pick Another Date"
Dim style = MsgBoxStyle.YesNo
Dim response = MsgBox(msg, style, title)
If response = MsgBoxResult.Yes Then
DateTimePicker1.Format = DateTimePickerFormat.Short
MsgBox("The Date Has Been Changed to " & _ DateTimePicker1.Value.ToShortDateString)
Exit Sub
End If
If response = MsgBoxResult.No Then
DateTimePicker1.Value = DateTime.Today
MsgBox("Keeping Today's Date " & Today.ToShortDateString)
Exit Sub
End If
End Sub