Access 2002
There are 4 fields on my form, StartDate, StartTime, EndDate and EndTime. EndDate + EndTime should always be larger than StartDate + StartTime. The first message box in the code below takes care of that.
A second message box has to come up as soon as the difference above is 6 hours or more asking if this is okay The box type is vbYesNo in this case.
Everything works fine, except that in the nested if...then clause below, when the user clicks the no-button in that message box, it does not take the focus back to the EndDate field like the first one does.
I think the mistake has to do with the value I use to refer to the clicking of the no-button. Does someone know what I'm doing wrong?
There are 4 fields on my form, StartDate, StartTime, EndDate and EndTime. EndDate + EndTime should always be larger than StartDate + StartTime. The first message box in the code below takes care of that.
A second message box has to come up as soon as the difference above is 6 hours or more asking if this is okay The box type is vbYesNo in this case.
Everything works fine, except that in the nested if...then clause below, when the user clicks the no-button in that message box, it does not take the focus back to the EndDate field like the first one does.
I think the mistake has to do with the value I use to refer to the clicking of the no-button. Does someone know what I'm doing wrong?
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If EndDate + EndTime < StartDate + StartTime Then
MsgBox "The end time must be later or the same " _
& "as the start time", vbInformation, _
"TIME ENTRY WRONG"
DoCmd.GoToControl "EndDate"
ElseIf ((EndDate + EndTime - StartDate - StartTime) * 24) > 6 Then
MsgBox "Are you sure you spent more than 6 hours " _
& "at the activity?", vbYesNo
If vbYesNo = 7 Then
DoCmd.GoToControl "EndDate"
End If
End If
End Sub
Last edited: