Unanswered: How can I make a button where one form closes as another opens?
I am making a start page to my DB with multiple buttons, I want a button to switch between different forms but I do not want there to be lots of them open after the user has selected a few different buttons.
Can I have a button to switch the current form (i.e. close one whilst opening another)?
Please can it be without this code I see all around the forum? If it needs code, can someone please tell me how to use it? Thanks
As far as I know, it cannot be done without some VBA code. one solution would consist in:
a) In a new Module (or an existing one), create the following procedure:
Public Sub CloseAllForms(Optional ByVal Except As String)
Dim obj As AccessObject
Dim dbs As Object
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
If obj.IsLoaded = True Then
If obj.Name <> Except Then DoCmd.Close acForm, obj.Name
b) In the module of every form that must close any other open ones when it opens, add the following procedure:
Private Sub Form_Open(Cancel As Integer)
If the other forms have a module already, open the Project Explorer from the VBA Editor (Ctrl+R) and navigate from Form Module to Form Module with it. If the other forms do not have a module, open every one of them in Design mode and create a module for every one of them.