Solved

Question using "Set frm = New Form_myForm"

Posted on 2009-07-03
6
305 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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.
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.
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…

758 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

18 Experts available now in Live!

Get 1:1 Help Now