requery a form by using window handle (hwnd) of that form (1 Viewer)

Mr.K

Registered User.
Local time
Yesterday, 21:19
Joined
Jan 18, 2006
Messages
104
How can I use the window handle to open a form, or better to set a focus to it or requery it? Getting the handle is quite easy : handle = form.hwnd but how can I use it after I have it?
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:19
Joined
Feb 19, 2002
Messages
43,233
Why would you ever need to? You can requery a form by using its name.

Forms!YourForm.Requery
 

Mr.K

Registered User.
Local time
Yesterday, 21:19
Joined
Jan 18, 2006
Messages
104
I have multiple instances of the same form open so I can't refer to the particular instance by using the name of the form.
I did bunch of searching and reading about it and I'm using a solution which uses window handles to keep multiple instances open. However, I can't find anywhere how to use the collection of window handles to then refer to a particular instance of the form.
(This is the solution which I'm using to open multiple instances: http://allenbrowne.com/ser-35.html)
 

macrena

macrena
Local time
Yesterday, 23:19
Joined
Aug 15, 2010
Messages
2
Hello Mr.K
Did you get a solution to this?
I have a form opened as an object (I have its hwnd in a golobal variable), and I need to bring the user back to a certain record after they've requeried the form from a subform control.
I would like to use the RecordsetClone of the parent, but I can't get a handle on it (sorry, pun intended)
Thanks,
Mac
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 13:19
Joined
Jan 20, 2009
Messages
12,851
Each instance of the form is a separate object. In order to persist that object it will have a variable name or be an item in a Collection.

If I remember correctly, Allen Browne's code uses the Hwnd as the index in a collection. The choice of the Hwnd is arbitrary. Any logical name could be used.

Either way the instance is easily referred to.

If the instance you wish to return to is the one whose index or name you stored as a global variable then simply refer to it.
 

macrena

macrena
Local time
Yesterday, 23:19
Joined
Aug 15, 2010
Messages
2
Hello Glaxiom,
Thank you for that reply.
The link you referenced tells how to create and remove a form from a collection.
I need to get the Recordsource (or SQL property) of a disconnected Grid (ADO) on the parent form object.
So do you know of any sites that describe how to reference a form object by its hwnd?

Referencing the object (in VBA) exposes ADD, COUNT, ITEM, and REMOVE

I have tried using frmMyFormObject.Item(lngHWND) but the error says "Subscript out of range".
When I try frmMyFormObject.Item(0), the error says "Subscript out of range".
When I try frmMyFormObject.Item(1), the error says "Type Mismatch"
When I try frmMyFormObject.Item(2), the error says "Subscript out of range".

So referencing the form object is only step 1 of my problem, but I'll be happy if I can figure it out.

Thanks again!
Mac
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 13:19
Joined
Jan 20, 2009
Messages
12,851
You cannot refer to a form by its Hwnd. You can loop through the Forms collection and test the Hwnd property until you find one that matches. However I cannot imagine why this would be necessary.

I can't understand what you are trying to do. Forget about the Hwnd and describe exactly what you have and what you are trying to do.

Do you have multiple instance of the same form as main forms? How are you persisting them as independent objects. Note that subforms don't have a Hwnd.
 

Users who are viewing this thread

Top Bottom