Solved

How to distinguish between instances of a subform from the subform's open event procedure.

Posted on 2011-09-15
14
321 Views
Last Modified: 2012-06-27
I plan to have several instances of a subform on a main form. I'd like the subform's open event code to distinguish one instance from another.

The only way I have thought of is to access the (e.g.) name property of the subform's container control. But I don't seem to be able to a access that control from within the subform's code.

I'd like to avoid writing any main form code.

 Any ideas?
0
Comment
Question by:ramrom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +4
14 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 125 total points
ID: 36543833
You'll find code that you can use here..
http://datagnostics.com/dtips/subform.html

for example...using the doubleclick event of a field in a subform..

Private Sub Order_ID_DblClick(Cancel As Integer)
         MsgBox ParentSubformControl(Me).Name
End Sub
0
 
LVL 10

Expert Comment

by:plummet
ID: 36543981
I'd add some code into the main form, I know you don't want to, but all you need to do is trap the enter event for the subform control, set a variable, and then you can use that to determine which one the user is in.

0
 
LVL 26

Expert Comment

by:Nick67
ID: 36544606
My understanding is that sub-objects (forms and report) are instantiated BEFORE their parents so what you have asked for is probably a non-starter
I guess really the questions to ask are:
<I'd like the subform's open event code to distinguish one instance from another>
Why? To what end and in what place would you use that distinguishing information?
And why only in the subform's code?
Why would you like to avoid writing the main form's code?

Because what you've asked for I think is impossible on the face of it.
And I don't say impossible in regard to Access very often.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36545015
ramrom,

As much this feature is requested (Creating "Instances" of a form).

I have never had a real, legitimate use for this.

As fellow expert,  can you explain what your ultimate goal is here, and why no other technique will get you what you are after?

Just curious...


JeffCoachman
0
 
LVL 75
ID: 36545265

"I have never had a real, legitimate use for this."
"Why? To what end and in what place would you use that distinguishing information?"

Somewhere I have a 12 month calendar, built with two physical objects ... a Main form and a Calendar form, used as a subform.  There are 12 instances of the same physical calendar form on the main form.  As well, there are various controls on the main form to change the Year, starting Month, and so on.  

So ... there is one minor example.

mx
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 36545294
Can I just make sure that you check out the answer provided by Peter?
That is an answer to the question asked.
(It's not the only way - I've offered a slightly alternate method here.)

As for form instances - firstly I don't think this is applicable.  It's just a turn of phrase.
Technically - subforms do exactly that, create instances of forms and are not limited to one per parent form, or simultaneously opened form.  Subforms do create instances that we take for granted - but they're not members of the forms collection (because they're subforms).

Actual instancing - well that depends on the business requirements.
If you have a search results form, say, and there is a business requirement that allows you to display a detail form for any of the returned matches - and not only one, but any result you want to open simultaneously - then form instancing is applicable.  It's just one of those "If you've never been asked for it, you've never needed it" scenarios.

Cheers
0
 
LVL 26

Expert Comment

by:Nick67
ID: 36545305
@mx
I can think of ways to use the same subform multiple times on a main form but I don't think you can code up anything to distinguish them from each other in the subform's OnOpen() event can you?

And if that isn't doable, then knowing a little more may help solve the OP's actual need rather than answering the nominal question.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 36545401
There's nothing wrong with the solutions suggested except, of course, that they are not and cannot be in the subform's OnOpen() event.
Which is what was asked.
Which I think may be impossible.

Hence I asked for more detail on why that particular event is the one being targetted.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 36545477
Except that they are able to be called in that event.
The load order of forms often has a bit too much stock put in it.  We're talking UI objects here, rather than data accessibility.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36545490
To All,

Yeah, I did not mean to hijack the thread, or change it's direction, ...it is just perhaps the entire concept of "Instantiating" a form has never been clearly explained in detail anywhere.

So I was just asking for the OPs reasoning...

I do think that this topic would be a great "Article" though...
Perhaps the confusion stems from the terminology "Copy"(an object) vs "Instantiate"(an object)


;-)

Jeff
0
 
LVL 26

Expert Comment

by:Nick67
ID: 36545739
Leigh,
I stand corrected.
Peter's solution can be called from the OnOpen() event.
Presumably yours can as well

@ramrom
The first post was the right answer.

Thank you both.
I learned something new
Nick67
0
 
LVL 17

Author Comment

by:ramrom
ID: 36554461
Thanks for the questions & comments. I come from Visual FoxPro which has a far better implementation of OOP than Access. I kep looking for ways to do in Access what is a no-brainer in FoxPro.

Peter's comment (#1) is how I have solved this problem in the past.I'm just looking for a better way.
0
 
LVL 26

Assisted Solution

by:Nick67
Nick67 earned 125 total points
ID: 36554543
There are some things we have to live without in Access.  Control arrays being one.  Some day if MS ever quits focussing on idiocy like SharePoint we may get stuff like that.
0
 
LVL 17

Author Closing Comment

by:ramrom
ID: 37021334
Thank you all for the efforts. Confirms my negative opinion of Microsoft.

I will continue to use the resource wasting strategy of examining every control to see if it is a subform.
0

Featured Post

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)

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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