I have a form "Form1" that opens another form "Form2" when button "Command1" in Form1 is clicked. As shown in the code below, control passes to Form2, and once the user does some stuff with Form2, Form2 either hides or closes itself and then returns control to Form1. Regardless of whether Form2 is hidden or closed, Form1 then does some stuff and closes Form2.
Private Sub Command1_Click()
DoCmd.OpenForm "Form2", , , , , acDialog
If CurrentProject.AllForms("Form2").IsLoaded Then
'Do stuff
End If
DoCmd.Close acDialog, "Form2"
End Sub
This seems to work fine first time that Form1 is opened. However, when I close and reopen Form1 and then repeat the above steps, Form2 does not appear and control passes directly to the If statement in the subroutine above. What's wrong? One clue is that CurrentProject.AllForms("Form2").IsLoaded seems to be permanently set to True after Form2 is opened the first time.
What's going on? How can I fix this? Thanks for any help.