Please explain why this scenario is occurring as I am baffled.
Below is the code I have on for the Data Entry Form OnClose Event on my form. I want to check to see if another form is open, and if not open it and then make it Visible. If the form is in layout view or design view then I don't want to automatically open the Main Menu Form. (Data Entry person should always have the Main Menu form open. Its visibility changes as the uses moves from one form to another.)
All forms are opened from the Navigation page for testing purposes.
Code:
Private Sub Form_Close()
Dim varTest As Integer
varTest = Me.Form.CurrentView
Debug.Print varTest
If Me.Form.CurrentView = 1 Then
Debug.Print "Form mode"
If CurrentProject.AllForms("mnuMainMenu").IsLoaded = False Then
Debug.Print "Main Form Closed"
DoCmd.OpenForm ("mnuMainMenu")
End If
Else
Debug.Print "Layout mode"
Exit Sub
End If
Forms!mnuMainMenu.Visible = True
Scenario 1 (results as expected)
Both Main Menu Form and Data Entry Form are open in Form view. Intermediate window displays the following:
Scenario 2 (results as expected)
Main Menu Form is Closed and Data Entry Form is open in Form view. Intermediate window displays the following:
Code:
1
Form mode
Main Form Closed
Scenario 3
Open and close Data Entry Form in Design view has no results in intermediate window regardless of whether Main Menu is open. (As expected)
Scenario 4
Main Menu Form is Closed and Data Entry Form is closed in layout view but was originally opened in Design view. Intermediate window displays the following when I close the form (As expected)
Now here is where it confuses me.
Scenario 5
Main Menu Form is Closed and I open the Data Entry Form in Layout view, this pops up in the intermediate window:
Code:
1
Form mode
Main Form Closed
And the Main Menu Form is opened.
When I close the Data Entry Form in layout view I get the following (As expected)
I think it is odd that when you open a form in layout view it triggers the OnClose event of the form. What is really going on in this instance?