Solved

Question using "Set frm = New Form_myForm"

Posted on 2009-07-03
6
327 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

809 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