Opening multiple copies of Form B from Form A

  • Thread starter Thread starter tina
  • Start date Start date
T

tina

i don't think you can have two instances (not copies) of the same object
open at the same time. but you could decide on a maximum number of
simultaneous open secondary forms you want to offer to your users (2? 3?
5?), then create FormB to suit your needs, and then make copies of the form
object in the database window, with new names, such as FormB1, FormB2,
FormB3. you can write code in FormA to check and see if FormB1 is already
open, if it is then open FormB2, if FormB2 is already open then open FormB3,
etc. you can also write code to close each of the FormB's if they're open,
when you close FormA. suggest you also write some code to *disallow* opening
two secondard forms to display the same detail record(s).

hth
 
You can instantiate a new "instance" of a form such that you can have
multiple windows of the same form open at the same time. Let's assume that
the form is named frmMyForm. The code to do this is as follows:

1) In the Declarations section of the module that will be instantiating the
forms, put these declarations (I'm assuming here that you would want up to
three instances of the form open at one time):

Private frmMyForm_Copy1 As Form_frmMyForm
Private frmMyForm_Copy2 As Form_frmMyForm
Private frmMyForm_Copy3 As Form_frmMyForm


2) In the code section where you want to make a new instance of the form
visible to the user:

Set frmMyForm_Copy1 = New Form_frmMyForm
frmMyForm_Copy1.Visible = True
' you can put code here to manipulate the form object
' and/or write values into controls on the form


3) You would do the same for other "instances" by using a different variable
(e.g., frmMyForm_Copy2).


4) Be sure to close the form when you're done with it. Note that you must
include in the frmMyForm a public function that will close that form so that
you can call that method to close the form in this case. For example, the
public function would be this:

Public Function CloseForm As Boolean
DoCmd.Close acForm, Me.Name, acSaveNo
CloseForm = True
End Function


Then you call this function this way:

frmMyForm_Copy1.CloseForm
' destroy the form object after closing the form
Set frmMyForm_Copy1 = Nothing

--

Ken Snell
<MS ACCESS MVP>
 
I guess I'm not understanding...

If you use the FormB to display a selected record, and you select a new
record and click the button, why do you need the "old" FormB? The record
that had been displayed won't be available any more, would it?

You've described a "how" (how you are trying to do something, with multiple
instances of FormB).

Can you describe "what" you are trying to accomplish? The newsgroup readers
may be able to offer alternate approaches if you explain a bit more what you
are trying to do...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 
You can also do it as a collection and open as many as you want (or have the
memory to handle):

Private Sub cmdInstance_Click()
Static colForms As New Collection

colForms.Add New Form_frmMyForm
colForms.Item(colForms.Count).Visible = True
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
I have a list of records in Continuous Form display - call it Form A. Each
record has a wizard-made command button next to the fields which opens up a
linked detail form - call it Form B. Right now, whenever I click on a
command button, Form B closes and re-opens with the details of the
associated record. What I want to do is to have two or more detail forms
open at one time. In other words, the current Form B should stay open and a
NEW Form B should appear with the details of the record in Form A that I
clicked on the button for. (And ideally all copies of Form B should close
when I close Form A, but that's a side issue).

I've read ACC2000, but that only seems to apply to opening another copy of
the form from itself; when I try and apply it to opening new copies of one
form from another I get error messages.

Thanks in advance for your help,

Jon.
 
Thanks for all the help.

The situation is that the client is using a summary list in continuous forms
view to select patients whose records they need to work on. When they select
their patient and click the 'Detail' button a detailed form page comes up.
Sometimes they'll be working on one record when they get a phone call
enquiring about some other patient. They want to be able to open the new
patient's detailed record and maybe work on it for a moment before closing
it and going back to the one they were on before.

Advice on any more straightforward methods is welcome.

Thanks again,

Jon.
 

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

Back
Top