Command Box question

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I have a database with 5 tables and corresponding forms.
I have the database open on the first form and then use
command boxes to get to all the subsequent forms. I
created them using the wizard, and selected "open form."
This is all well and good, but there's too much clutter,
so I was wondering how to get the command button/box to
open the form I want it to open, and close the one that is
currently open, so that there is only one form open at a
time. I went to the properties screen and saw the code
that it used to open the next form, and tried adding in
some syntax that would close the current form, but no
dice. Could someone tell me if/how to get the current
form to close, and if it involves modifying the VBA code,
what the appropriate syntax is? Thanks.
 
Hi,
You can do it with a bit of code like this:
Place this Sub in a standard module.

Public Sub CloseForms(strName As String)
Dim frm As Form
For Each frm In Forms
If frm.Name <> strName Then
DoCmd.Close acForm, frm.Name
End If
Next frm
End Sub


Now, place this code in each command button click event
before the code opens a form:
CloseForms Me.Name

THis will close any open forms except your 'first form'.
 
Back
Top