storing window handle

Mr.K

Registered User.
Local time
Today, 16:16
Joined
Jan 18, 2006
Messages
104
I have multiple instances of the form open. Whenever an instance gets focus I gather its window handle. I wish to store this window handle "somewhere" so then I can refer to it as the last instance that had focus.
My question:
where should I store it? In a global variable or a table? It will be a single number that would be replaced each time the new instance gets focus. Also if it is a global variable how can I refer to its value in my vba? (e.g. instance_handle = 2342342; can I just call it then from another place using that name?)
 
possible solution

Just wanted to add a post on how I proceeded (someone may find it useful):

I used a table to store the WindowHandle and each time a new instance of my form gets activated I update the record with its handle. Then I Dlookup the handle when I need to refer to the Last Instance.

I use the following code to return index for Form(index) as LastInstance so I can refer to the last instance when needed:
Code:
Function LastInstance()

Dim instance As Long
Dim lng As Integer

instance = DLookup("[instance]", "tblInstance", "ID = 1")
For lng = 0 To Forms.Count - 1
    If Forms(lng).hwnd = instance Then
        Let LastInstance = lng
    Exit For
    End If
Next

End Function
 

Users who are viewing this thread

Back
Top Bottom