Closing forms, help please.

C

CEL504

Could someone give me some advice please. I have a switchboard form in my
database and from here I move to other forms and then return to the
switchboard after reviewing, how do I get the forms to close when I return to
the switchboard again? I have read a few of the threads, yet still can't get
my head around it at the moment. Any advice would be greatly appreciated.
 
P

PieterLinden via AccessMonster.com

CEL504 said:
Could someone give me some advice please. I have a switchboard form in my
database and from here I move to other forms and then return to the
switchboard after reviewing, how do I get the forms to close when I return to
the switchboard again? I have read a few of the threads, yet still can't get
my head around it at the moment. Any advice would be greatly appreciated.

Are you sure you want to do that? If you _really_ want to do that, you could
write some code that closed all open forms except the switchboard whenever
you set focus to the switchboard form.

That's a weird way of doing things... at least to me. Normally you close
your forms explicitly. If you're sure you want to cause this to happen, this
should do it.

Private Sub Form_Activate()

Dim frm As Form
Dim i As Integer

' create an array of form names
Dim frmName() As String
ReDim frmName(Forms.Count)

' populate the array with names.
For Each frm In Forms
i = i + 1
frmName(i) = frm.Name
Next frm

' dimming a variable here is bad programming...

Dim intX As Integer
' loop through the array
For intX = 1 To i
If frmName(intX) <> Me.Name Then '--- don't close the
switchboard...
DoCmd.Close acForm, frmName(intX), acSaveNo
End If
Next intX
End Sub
 
L

Linq Adams via AccessMonster.com

I have to agree with Pieter, this is a strange approach! Why not simply close
the form? If the Switchboard is still open focus will then return to it.
 
R

Rob Parker

Did you see this reply I posted to your previous post of this same question
a few days ago?


If you're really wanting to control the user interface to prevent people
from having lots of different forms open at the same time - due to the
switchboard form being always available - then the easiest way is to hide
(rather than close) the switchboard form when another form is opened, and
show it again when the other form is closed. To do this, you'd use code
such as this:

In the event of the button on the switchboard form to open the new form:
Me.Visible = False
DoCmd.OpenForm "frmNewFormName"

In the close event of frmNewFormName:
Forms("frmSwitchboard").Visible = True
Putting this code in the Close event of the form ensures that it will always
run, regardless of how the user closes the form. If you've set up your form
(and menus) so that the user can only close the form via a command button
you have supplied, then you can put this code in the Click event of your
close button.

HTH,

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Closing forms help please, 2
Closing Forms. 5
Switchboard and Closing Forms 4
Form Closing. 1
Help with form 0
Corrupt PST 2x/week HELP! 0
Switchboard Form 3
should i hide a form or make it modal 4

Top