How to access an instance of a form in forms collection

K

Kamil Dursun

Hi,

I define a new instance of a form as

dim Frm(10) as Form_MyForm

such that I can open 10 instances of the same form.

Later I define new instances as

set Frm(n) = New Form_MyForm

several times. I now have several MyForms on my desktop. The addresses are
stored in Frm(n)

I want to access the data on one of Frm(n) from another module but I have
problems.

I cannot find out the index number of Frm(n) in Forms collection. Neither
can I pass the address of Myform to another module.

I will appreciate any help.

Thanks - Kamil
 
A

Albert D. Kallal

The question is what or "when" is the code to run?

for example:

Public Function AskInvoicePrint()

Dim tblgroupid As Long
Dim frmActive As Form

Set frmActive = Screen.ActiveForm

tblgroupid = frmActive.frmMainClientB.Form!ID

If frmActive.InvoiceNumber = 0 Then
frmActive.InvoiceNumber = nextinvoice
frmActive.Refresh
End If

So, in the above code, no matter what routine called the above, you can pick
up the active form.

You can also in your forms code go:

Call MySubRoutine(me)

And then in an standard code module go:

Public Sub MySubRoutine(f as form)

in this code, we can reference the current instance of the form
with "f"

So, the question here is what/when/how/were you code is going to be called,
and if you want to pick up the current instance of the form by using
"screen" or your code can pass the form reference as in the 2nd example
above.

So, when you say you can't find the index, I not sure it matters. Just pass
the current instance of the form in the calling code. Or, have the code pick
up what form has the focus.
 

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

Top