Make Switchboard the active window?

P

Pat Dools

Hello,

I have the following code to close the current form, and then make the
'Switchboard' form (which is already 'open'), the active window:

Private Sub CommandCloseFormGoToSwitchboard_Click()
DoCmd.Close
DoCmd.OpenForm "Switchboard", , , acNormal
End Sub

I have it behind a Command button. When I click on the button, I get an
error that the form cannot be opened because it is not bound to a table or
query. The Switchboard is not in fact bound, the user simply launches
various forms from it. So, I'm confused as to why it is looking for a data
source underneath.

Is there code to simply close th active form and make the 'Switchboard' the
active window?

Thanks.
 
A

Allen Browne

Suggestions:

1. If the form is already open, you can just SetFocus to it:
Forms!Switchboard.SetFocus

2. If the switchboard form was created by the wizard, then it is bound to a
table that contains the switchboard items, so there could be a problem in
retrieving that data.

3. For closing the form that the code resides in, rather than just Close,
you might try:
DoCmd.Close acForm, Me.Name
The advantage is that if the code is called from elsewhere, it closes the
right form.

4. If that current form is bound, and the record is being edited, there is a
problem where the Close action silently loses an entry that cannot be saved.
So, you probably want to explicitly save first. Details in:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

5. Another approach is to set the Close event of all your forms and reports
(other than the switchboard) to call a function. This function looks through
the open forms and reports, and if there are no visible ones, it opens the
switchboard automatically. Here's the code for the function:
http://allenbrowne.com/unlinked/Keep1Open.txt
 

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

Top