I have a form "Form1" with a command button that when clicked, hides itself, and then opens another form "Form2" as follows:
Private Sub Command1_Click()
Me.Visible = False
DoCmd.OpenForm "Form2"
End Sub
The Form_Open subroutine of Form2 contains a check for errors. If an error is found, I want Form2 to display an error, close Form1, and then close itself:
Private Sub Form_Open(Cancel As Integer)
AnError = 'check for an error
If Not AnError Then
'things are OK
Else
Response = MsgBox("There was an error in Form2.", 0, "Form2 error message")
DoCmd.Close acForm, "Form1"
DoCmd.Close
End If
End Sub
I've tried numerous variations on this scheme for opening and closing the forms, and all fail in different ways. This particular one seems to do everything except actually close Form2 after the error message is displayed.
Once again I'm baffled about the way Access 2010 VBA handles the opening and closing of forms; the reference information at MSDN is atrocious. Thanks for any help.