I've been using the following code to close all forms but 1 and it has been working fine. I added a new sub-form to my main display form and now the code doesn't function properly. My forms are indexed 0 - 3 and I need to keep index 0 open.:
Dim intX As Integer
intX = 1
DoCmd.Close acForm, Forms(intX).Name
intX = 1
DoCmd.Close acForm, Forms(intX).Name
Do While Forms.Count > 1
DoCmd.Close acForm, Forms(1).Name
Loop
This use to work fine until I added the subform. Now, on-click event the code closes index #1, leaves 2 & 3 open (which are now numbered 1 & 2). If I hit the on-click event again, it closes 1 & 2 and leaves 0 open. I can't figure out why it takes 2x to close all the forms now while leaving index 0 open. I'm still learning VBA so excuse my lack of total understanding. Thanks!