Solved

Question using "Set frm = New Form_myForm"

Posted on 2009-07-03
6
312 Views
Last Modified: 2013-11-28
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_...")?
0
Comment
Question by:MitchellVII
  • 3
  • 2
6 Comments
 
LVL 84
ID: 24774148
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 ...


0
 
LVL 5

Author Comment

by:MitchellVII
ID: 24774205
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?
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 24774234
In order to open multiple forms you MUST set those new instances to a "New" instance of the form, so no, you cannot do this without using the New keyword.

I'd perhaps agree with you regarding multiple instances, and there is some discussion going on about this in the MVP newsgroups ... I'm not sure it's a greatly needed feature, but I can see where it would be helpful at times. That said, many users would get very confused working with the same form (different data) and could (almost certainly would) end up altering the wrong data or some such. With data-centric apps, to me SDI interfaces (at least from the standpoint of a single form) are a much better alternative.

Can you describe more of what you're doing, and why multiple instances of the same form would be beneficial?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 5

Author Comment

by:MitchellVII
ID: 24774320

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.
0
 
LVL 57
ID: 24777292
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.
0
 
LVL 5

Author Comment

by:MitchellVII
ID: 24778077
Thanks Jim :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now