Button opens new form, closes current.

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Hello,

I have created a series of forms that flow in to each
other starting from a main, central page. The first page
has several buttons on it that will open desgnated forms,
that will also have buttons on them to open other forms,
further down the chain. When I click on a button to open
a form the current form remains open. I would prefer it
to close the current form so that there is only one form
on the page at any time. That way I can add a button to
each form that takes the form back to the previous one,
or the main page, so people can pretty much get around,
without having to close loads of forms.

TIA,

Phil
 
Phil,

It's quite easy to do that, but it's preferable to just make forms invisible
temporarily rather than just closing and reopening, especially if they take
some time to load (which would probably be the case in a multi-user
environment over a LAN). To do that, take the following steps:

On each form except the very first one, add an unbound textbox called, say,
CallerForm, and set its Visible property to No. Its purpose will be to store
the name of the form that opened it, so as to remember which form to turn
back to visible on closing, so the user need not see it.
Next, modify the code behind the button on each form that opens another form
as follows: where the code is:
stDocName = "FormX"
DoCmd.OpenForm stDocName, , , stLinkCriteria

change it to:
stDocName = "FormX"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms(stDocName)!CallerForm = Me.Name
Me.Visible = False

Finally, paste the following line of code in each form's On Close event
(except for the very first one):
Forms(Me.CallerForm).Visible = True

HTH,
Nikos
 
Phil,

On second thought, you could do the same without the hidden textboxes, if
you are not using OpenArgs for anyhting else. To do it, change the code
behind the button on each form that opens another form from:
stDocName = "FormX"
DoCmd.OpenForm stDocName, , , stLinkCriteria

To:
stDocName = "FormX"
DoCmd.OpenForm stDocName, , , stLinkCriteria , , , Me.Name
Me.Visible = False

And set the code in the On Close event of all but the first form to:
Forms(Me.OpenArgs).Visible = True

HTH,
Nikos
 
Back
Top