[AccessD] Multi-Instance Forms re-visited

Ken Ismert KIsmert at TexasSystems.com
Wed Dec 15 17:58:27 CST 2004


Francisco,

One caution: in A2K Help, under "hWnd Property", it says:

>> Caution: Because the value of this property can change while a program is
running, don't store the hWnd property value in a public variable.

So, it is probably not a good idea to key your form collection with hWnd, as
it could potentially change over the life of the form. Better to generate
your own unique index within clsMultiInstance, and pass that to the form via
a property.

Upon reading your code, I noticed three issues:

(1)
>Public Property Let Form(frm As Access.Form)

Object properties should use 'Property Set'.

(2)
> Sub Add(frm As Access.Form, hWnd As String,
>   . . .
>       x.Form = frm

Should read:
        Set x.Form = frm

(3)
The easiest way to get your form collection to persist is to declare a
public variable:

        Public MultiForms As New clsMultiInstance

The Public scope will keep the MultiForms reference, and the forms it
manages, alive until the user exits (or the Interpreter gets reset). The New
keyword guarantees that MultiForms will auto-initialize on first reference.
Although others in this forum may not prefer this approach, I have used it
for years, with no discernable downside. The upside is you can use the
MultiForms reference directly when adding a new form, without having to put
calls to a setup routine throughout your code.

-Ken

>From: Francisco Tapia [mailto:fhtapia at gmail.com]
>Sent: Wednesday, December 15, 2004 4:47 PM
>To: Access Developers discussion and problem solving
>Subject: Re: [AccessD] Multi-Instance Forms re-visited

>This code works for displaying "one" form... but it does not give
>me a tolorance to opening a 2nd Form... :(, the original code
>worked fine for many forms... Ideas?





More information about the AccessD mailing list