Link to home
Start Free TrialLog in
Avatar of MitchellVII
MitchellVIIFlag for United States of America

asked on

Question using "Set frm = New Form_myForm"

Hi All,

I have created a new pop-up form that I want to be able to create multiple instances of.  To do this I am using:

Dim frm as Form
Set frm = New Form_myForm

My question is, I want to be able to somehow pass the form name to be opened to this via an argument in a function, like so:

fOpenForm(myFormName), and then have it activate like this:

Set frm = New Form_ & myFormName

although I know this doesn't work.  Any ideas how I can pass different form names to "New Form_...")?
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

AFAIK you cannot do this ... this is an example of early binding, and in order to do this the compiler would have to know what, exactly, to "bind" ... if you use a variable the compiler would have no idea what type of object to expect and would choke.

You might try something like this:

Function fOpenForm(FormName As String) As Form
  Dim frm As Object

  Set frm = forms(FormName)
  Set fOpenForm = frm
End Function

Then call it like this:

Dim frm As Form
Set frm = fOpenForm("frmCustomers")

I'm not sure this will work, but it may ...


Avatar of MitchellVII

ASKER

I think most of my confusion comes from trying to use the "New Form_" thing to open a form so that i can open multtiple instances of the same form.  I really don't understand why Access doesn''t make this sort of thing easier since it is something pretty much anyone might want to do.

Is there a way to open multiple instances of a form WITHOUT using the "New Form_" syntax?
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

LSM,
In my database, I have continuous records forms that utilize some pretty cool "drag n' drop" code I wrote for moving records around.

One thing i wanted to be able to do is have a pop-up "detail" form that would appear and then drag to wherever I wanted to work on it when I clicked on a field.  The benefit of being able to do this with mutpiple forms is that i could compare the details on multiple records simultaneously.

For example, the idea is that I can click on a simple "Log_ID" Field on my continuous form as a little Detail Popup Form for that Log Entry would appear and I could drag it to a spot i wanted to work on it.
I was just trying to streamline the process by passing the popup form name as an argument, but since i can't do that with " New Form_...", I just write a Select Case statement and iterate through the 8 possibiltiies, kind of like this:

'Open Snapshot PopUp:
Select Case strDragSnapshot
    Case "ContactSnapshotEdit"
        Set frmDrag = New Form_ContactSnapshotEdit
    Case "JobSnapshotEdit"
        Set frmDrag = New Form_JobSnapshotEdit
    Case "MatchSnapshotEdit"
        Set frmDrag = New Form_MatchSnapshotEdit
    Case "BookingSnapshotEdit"
        Set frmDrag = New Form_BookingSnapshotEdit
    Case "LogSnapshotEdit"
        Set frmDrag = New Form_LogSnapshotEdit
    Case "JournalSnapshotEdit"
'        Set frmDrag = New Form_JournalSnapshotEdit
    Case "DocumentSnapshotEdit"
        Set frmDrag = New Form_DocumentSnapshotEdit
    Case "PostSnapshotEdit"
        Set frmDrag = New Form_PostSnapshotEdit
End Select
Anyway, it may be kludgey, but it works fine so I'll go with it.
You might want to pick up a copy of the Access Developers Handbook published by Sybex.  It includes code for handling multiple form instances via a user defined collection.
That code also includes logic to manipulate the caption of each form so you have better control over them.
It also has a section on doing multiple instances for pop-up forms.
JimD.
Thanks Jim :)