docmd.openform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Access 2000
Does using docmd.openform when the form is already open cause another
instance of the form?
Will resources diminish if the form is not explicitly closed before opening
it again?
The form may be opened many times and there seems to be no ill effects:
DoCmd.OpenForm "frmRolodex", acNormal, , "Name Like '*" & gstrFind & "*'"
 
Try it.

Did you see another instance open?
Did the existing instance get focus?
Did the new WhereCondition get applied?

Or did it just leave the existing instance open in the background and
without the new WhereConditon applied?

There is no issue with resources.
 
No, it does not open another instance. If the form is already open the
Docmd.openform merely acts like Docmd.selectobject which sets focus to the
named form.
 
ACC2000: How to Open Multiple Instances of a Form
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q210248

ACC: How to Open Multiple Instances of a Form
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q135369

For each new instance you need an form object variable which you set using
the New keyword. Once you have the form open you can change it's
recordsource and caption.

Be careful

- the form that you are instancing must have a module (ie it can not be a
lightweight form).

- the form object variable is the best way to refer to this new instance
since you will not be able to find the form in the forms collection (unless
you know it's index).

- As soon as your object variable goes out of scope, the new instance of the
form will automatically be destroyed (and closed).

Here's some sample code that uses the selected rows in a listbox to open
multiple instances of the customer form.

Note that col is declared in the Module header so that it stay's in scope
until the current module terminates.

Dim colForms As Collection
Private Sub Command2_Click()
Dim varItem As Variant
Dim frm As Form
Set colForms = New Collection
For Each varItem In Me.List0.ItemsSelected
Set frm = New Form_Customer
frm.RecordSource = "Select * from Customer " _
& "Where Custid=" & Me.List0.ItemData(varItem)
frm.Caption = "Customer: " & Me.List0.Column(1, varItem)
colForms.Add frm
Next varItem
End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

How would I get it to open another instance??

Sandra Daigle said:
No, it does not open another instance. If the form is already open
the Docmd.openform merely acts like Docmd.selectobject which sets
focus to the named form.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Access 2000
Does using docmd.openform when the form is already open cause
another instance of the form?
Will resources diminish if the form is not explicitly closed before
opening it again?
The form may be opened many times and there seems to be no ill
effects: DoCmd.OpenForm "frmRolodex", acNormal, , "Name Like '*" &
gstrFind & "*'"
 
James said:
When I opened the form the old way, (using DoCmd.OpenForm) I was able
to pass OpenArgs to the next form. Is there a way to do this with
your example?

As you've already noted, OpenArgs won't work with forms opened this way so
you have to instantiate the form and then set the values of public
variables or controls on the form. You can embellish on that a bit by
wrapping the Public variables with custom properties but it still doesn't
change the interface mechanism. Instantiate the form, then set a variable or
property.

The problematic thing about this for me is that it's harder to ensure that
the needed variables are getting set by the calling code. One approach that
I use is to create a wrapper function that returns the new instance of the
form to the calling code. Create required (and typed) parameters in the
wrapper function and then let the wrapper function handle the opening of the
form and setting of variables
 
Actually you are worng on that Access 2000 opens another instance of the form
if you run the "docmd.openform"...

Sandra Daigle said:
No, it does not open another instance. If the form is already open the
Docmd.openform merely acts like Docmd.selectobject which sets focus to the
named form.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Access 2000
Does using docmd.openform when the form is already open cause another
instance of the form?
Will resources diminish if the form is not explicitly closed before
opening it again?
The form may be opened many times and there seems to be no ill
effects: DoCmd.OpenForm "frmRolodex", acNormal, , "Name Like '*" &
gstrFind & "*'"
 
Did you try it before contracting Sandra?

Might have saved you some embarrassment.
 
Back
Top