My form is based on an ask query (2 table, multi-field primary key). Once the user answers the prompts I have written code to check to see if one of the fields for the primary key is empty. The way it is set up, if one field is empty, there is no record in the underlying table. In the case of no records, the form is supposed to close and open another form where the use can enter data. I can get the other form to open, but no matter what I do, the original form stays in front or using the DoCmd to close it causes an error.
I have tried adding code to the OnLoad and the OnOpen to perform the check for an empty field and change forms, but can't seem to get it to run at all.
The SetFocus line under Case Is came about because if I don't change the focus, the MsgBox runs twice (I think once for each field in the ask query that the user needs to enter criteria for).
Also, from the ...Close ac form, "frmModifyPaySheet"....
line an error is produced:
"This action can't be carried out whlie processing a form or report event"
I realize this may be "long winded" and fragmented, but I don't know how else to explain it. Thanks for any help.
Here is my code:
I have tried adding code to the OnLoad and the OnOpen to perform the check for an empty field and change forms, but can't seem to get it to run at all.
The SetFocus line under Case Is came about because if I don't change the focus, the MsgBox runs twice (I think once for each field in the ask query that the user needs to enter criteria for).
Also, from the ...Close ac form, "frmModifyPaySheet"....
line an error is produced:
"This action can't be carried out whlie processing a form or report event"
I realize this may be "long winded" and fragmented, but I don't know how else to explain it. Thanks for any help.
Here is my code:
Code:
Private Sub Initials_GotFocus()
Dim myValue As Variant
myValue = Me.Initials
myValue = IIf(IsNull(myValue), 0, myValue)
Select Case myValue
Case Is = 0
Me.butCloseModifyForm.SetFocus
MsgBox "You do not have a pay sheet started" & _
" for that week." & vbCrLf & "You will be taken to" & _
" the Enter Pay Sheet Form"
DoCmd.OpenForm "frmPayroll_Entry"
DoCmd.Close acForm, "frmModifyPaySheet", acSaveNo
Case Else
End Select
End Sub