[AccessD] Multi-Instance Forms re-visited

Ken Ismert KIsmert at TexasSystems.com
Fri Dec 17 11:31:49 CST 2004


Jim, Mark, Francisco,

>I believe Hwnd is unique as well.
>
>Jim

See the Note in "hWnd Property",

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/v
bprohwnd.asp

What Microsoft is saying in this topic, and the Access Help topic, is that
while the hWnd for a window will be unique, you can't count on it to keep
the same value over time.

So, if you key your form collection using hWnd, any function tries to find
the form instance in the collection based on the  current hWnd is not
guaranteed to work. The hWnd will still be unique, it just may not be the
same value you stored when you added the form to the collection.

In one of my object form managers, I use a class module-level variable to
guarantee a unique, stable ID:

Private lIDCounter As Long

Public Sub AddForm(rFrm As Access.Form)

    Dim sID As String

    lIDCounter = lIDCounter + 1
    sID = CStr(lIDCounter)
    colForms.Add rFrm, sID
    rFrm.SetInstanceID sID

End Sub

Of course, each form participating in this scheme now needs to have a
SetInstanceID method:

Private sInstanceID As String

Public Sub SetInstanceID(sID As String)
    sInstanceID = sID
End Sub

Now the form, when it is calling back to the managing object, can use its
sInstanceID to identify itself.

This is extra work, but do you want to be 99% sure your Form ID solution
will work, or 100%?

-Ken





More information about the AccessD mailing list