I have a database with multiple little forms spread out across the database (as most are I'd assume, lol). There are multiple ways to get to multiple different forms, however I ran into a bit of a naviational issue that in certain circumstances, when a user closes a form, nothing else opens or is open. So I'd ideally like Access to check if any forms are open at any given moment, and if not, then to open a specific form (the databases "main" form). I googled this and couldn't find what I was looking for (possible I google the wrong thing?), so I honestly don't really know where to even start.
I would like to create a function that I execute on Form_Close in order to check if any forms are currently open, and if not, to open a specific form. Again, I'm not even remotely sure of where to even start looking for this answer, so I don't really have anything to start off my journey.
Add a comment
|
1 Answer
An easy way would be this:
Add this procedure in a standard module and edit the main forms name in there:
Public Function OpenMainFormIfThisIsTheLastForm()
If Forms.Count = 1 Then DoCmd.OpenForm "YourMainForm"
End Function
In each form you want to open the main form before itself closes place this in the On Close-event:
=OpenMainFormIfThisIsTheLastForm()
That should be all.
3 Comments
BeardedSith
How would I add Reports in that, too? I tried
if Forms.Count = 1 And Reports.Count = 1 but nothing happened. Should it be Or? I assume Or would cause issues because if there's a form open but you're closing a report, then things would go weird.AHeyne
Try
If (Forms.Count + Reports.Count) = 1 Then DoCmd.OpenForm "YourMainForm".BeardedSith
Once again you are amazingly fast and dead on. Thanks a million!