Code keeps going to next record

  • Thread starter Thread starter Paul Scott
  • Start date Start date
P

Paul Scott

I have a DateAssigned field. When a button is clicked the
code checks if the DateAssigned field is null. If the
field is NOT null the user receives a Yes/No/Cancel
message. This part of the code works great.

What I'm having a problem with is the next part of the
code when the DateAssigned field IS null. When the button
is clicked the user receives a Yes/No message. If the
user clicks Yes the user is taken to the next record
which is correct. The problem is when the user clicks No.
The current form is supposed to close and another forms
opens. But instead the user is taken to the next record
just like if they clicked Yes.

I have the code listed below. I would be appreciated if
someone would look over the code and see what I'm doing
wrong.

Private Sub cmdSaveHKWO_Click()

If IsNull(DateAssigned) Then

Select Case MsgBox("You didn't enter a date in the
Assign Cleaned Date." & vbCrLf & " " & vbCrLf & "Click
Cancel to return to the form and enter a date." & vbCrLf
& " " & vbCrLf & "Click Yes to go to the Next record." &
vbCrLf & " " & vbCrLf & "Click No to return to the Main
Housekeeping database.", vbYesNoCancel)

Case vbCancel

Me.DateAssigned.SetFocus
End

Case vbNo

DoCmd.Close acForm, "frmHousekeepingAssigned"
DoCmd.OpenForm "frmMainHousekeepingWO"
DoCmd.Maximize
End

Case vbYes

DoCmd.GoToRecord , , acNext
DateAssigned.SetFocus
End

End Select

ElseIf Not IsNull(DateAssigned) Then
MsgBox "Click Yes to go to the next record. Click No
to return to the Main Housekeeping database.", vbYesNo
DoCmd.DoMenuItem acFormBar, acRecordsMenu,
acSaveRecord, , acMenuVer70
DoCmd.GoToRecord , , acNext
DateAssigned.SetFocus

Else

DoCmd.Close acForm, "frmHousekeepingAssigned"
DoCmd.OpenForm "frmMainHousekeepingWO"
DoCmd.Maximize

End If

End Sub


Thanks all,

Paul
 
ElseIf Not IsNull(DateAssigned) Then
MsgBox "Click Yes to go to the next record. Click No " _
& "to return to the Main Housekeeping database.", vbYesNo
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.GoToRecord , , acNext
DateAssigned.SetFocus

the first part of your code has a Select Case statement to handle the 3
available choices from that message box, but the above code does nothing at
all to handle the 2 choices available from its' message box. you have to
write code to do that, same as you did for the other message box.

hth
 
Back
Top