referring to form by using its index number

Mr.K

Registered User.
Local time
Today, 03:49
Joined
Jan 18, 2006
Messages
104
How can I refer to a form by using its index number? Also how can I retrieve an index number of a form?

(I'm opening multiple instances of the same form and read that the only way to refer to those instances is by using their index number. I found some solutions that use hWnd as well but I can't get any further support on it as far as referring to a form by using the window handle so I'm trying to capture and then use the index number)
 
still in a dead corner

That's the link that got in me in "trouble". It shows how to open new instances, etc.. but not how to refer to them later from different forms. So I thought of using the Form index number, but can't find the proper syntax anywhere for:
1. getting the Form index number
2. referring to the form by using its index number
 
Try this...

I just came across your topic because I was looking for something similar. Not sure if you found a solution yet but I do the following to determine the form index:

For FormIndex = 0 To Forms.Count - 1
If Forms(FormIndex).Hwnd = Me.Hwnd Then
MsgBox ("My FormIndex = " & Str(FormIndex))
Exit For
End If
Next

The Hwnd is unique, so it should also work if you use multiple instances of the same form. Keep in mind that both the Hwnd and Index of a form might change during the time your application is running.

Rgds,

Frank
 
Using form index in references

With regards to the syntax how to use the form index in references, these are all possible options, including using the index:

Syntax: Forms!formname
Example: Forms!OrderForm

Syntax: Forms![form name]
Example: Forms![Order Form]

Syntax: Forms("formname")
Example: Forms("OrderForm")

Syntax: Forms(index)
Example: Forms(0)

Keep in mind that if the form name includes a space, the name must be surrounded by brackets ([ ]).

A reference to a control called MyControl on the form with form index = 1 should look like:
Forms(1)!MyControl

Rgds,

Frank
 

Users who are viewing this thread

Back
Top Bottom