another way of opening a form

  • Thread starter Thread starter lei
  • Start date Start date
Well, there is, but as a general rule, you want to use the standard approach
to opening a form, and docmd.OpenForm
is that standard approach.

if you do NOT use docmd.OpenForm, then the forms() collection is NOT
correctly setup (and that is not good).

However, you can (and often do need) to open multiplies instances of the
same form.

This is allowed in ms-access, and you can't use OpenForm in this special
case.

You can references the base class object of the form (not a good idea), and
simply make the form visible:

form_YourFormName.Visible = true

The above will load the form. Note that all events fire when you do this
(open, load, etc). The above also requites that the form have at least
"some" code, as then ms-access assumes the form is really a class object
(and, any public function declared in the form will appear in inteli-sense
as a method of the form when you do this!). There are several downfalls of
using the above approach (perhaps the largest problem is the loss of my most
favorite ms-access feature:

The where clause of the OpenForm

The other issue that an come up is that when a form is used as a sub-form,
then a reference the base class object actually references that sub-form,
but if more then on instance of the form is opened, then it does not (this
occurred in a97...I think the later versions don't have this sub-form
problem).

At any rate, you do want to be careful.

You can also launch two copies of the same form like


dim f1 as new form_YourFormName
dim f2 as new form_YourFormName

f1.Visible = true
f2.Visible = true

Note that if vars f1 and f2 go out of scope, then the forms will close....

The best approach is generally to define a global collection that will hold
these forms..and add them to that...

By the way, why do you want to use something different then docmd.OpenForm ?

As mentioned, with the options it has...you generally save tons of
coding....(you can pass the form pars via openargs, and you can pass
filters, and you can pass a sql where clause, and you can set the form to be
dialog (which you can't do any other way but via OpenForm).

DoCmd.Open is in fact one of the keys as to why ms-access is so productive.
You can open a form to a particular invoice number with ONE LINE of
code....now that really amazing to me!!
 
Back
Top