Code for multiple form instances

jighead

New member
Local time
Today, 12:50
Joined
Jan 12, 2009
Messages
7
I've copied some code from the Access 2007 VBA examples for opening multiple form instances. It works when I open the example db, but gives me a "User-defined type not defined" when I use it. I have looked at the references from the example db, and made sure that I have VB for Apps, MS Access 12.0 Object Library, OLE Automation, and MS Office 12.0 Access database engine Object in my references.

When I try to open a form with this code, it seems to fail on the "New Form_" bit.

Code:
Option Compare Database
Option Explicit
'This sample demostrates how to use multiple instances of a form.
'Declaring global variable to create collection
'to hold multiple instances of a form.
Private mcolFormInstances As New Collection

Function OpenFormInstance(FormName As String, Optional WhereCondition As String, Optional SetEnable As Boolean)
'Declare the Form Object
Dim frm As Form
Select Case FormName
   Case "frmInvDetail"
       Set frm = New Form_frmInvDetail        
   Case Else
       Debug.Assert False
End Select

'set the filter properties on the form.
If WhereCondition <> "" Then
    frm.Filter = WhereCondition
    frm.FilterOn = True
End If

'Now make the form visible.
 frm.Visible = True
    
    ' Need to keep a reference to the form so that it doesn't immediately
    ' close when the frm variable goes out of scope.
 mcolFormInstances.Add frm
End Function

Can anyone help me figure out why this won't work, or suggest a better way to do it?
 
The yellow arrow is pointing to:

Function OpenFormInstance(FormName As String, Optional WhereCondition As String)

but this is "selected":

New Form_frmInvDetail
 
As I am looking at this again today, I notice that when I open the Object Browser, frmInvDetail is not listed as an object in my project. How do I get the Object Browser to see this form?

I suspect that the type definition error is because the module knows nothing about frmInvDetail. I can see my other main form in the Object browser, but not this one.

Thanks
 
That's just because it probably doesn't have any code on it. If it has no code, it doesn't show up in the object browser. But that shouldn't make a difference. You can check it out by trying to use the other form instead and see if it works with it. I was playing with it last night but couldn't figure it out. I haven't done the multiples of the same form stuff (I've seen it done, but haven't used it myself).
 

Users who are viewing this thread

Back
Top Bottom