Full Version: Multiple subform instances
UtterAccess Forums > Microsoft® Access > Access Forms
Ooooooo, I got a fun one for you...


Main form holds two copies of the SAME subform. We'll call the first, SubformA, and the second, SubformB.

During the subform's BeforeInsert event, a small amount of code runs. If a record is added using SubformA, x (some variable) needs to be 1. If a record is added using SubformB, x needs to be 2.

How do you determine which subform is being used and run the appropriate code? I can think of some very awkward ways of doing this, but nothing elegant comes to mind.

Any takers?
You could use the Enter event of each of the subform container controls to set the value of x. Each container control is specific to one copy of the subform.
Do you mean in some global variable? That was one of the clumsy ways I was trying to avoid. I suppose I could create a control on the Main Form and update it with the value instead of a GV.
e'll call that option B. A good option, but let's see if anything else pops up....
Any other ideas.
I was hoping someone would come up with something like...
..something along those lines.
?Am I missing something - didn't your Q ask how to set a variable X based on which subform was used?
Yes, just not a global one. -- or one outside the subform's scope.
Yjust not a global one. -- or one outside the subform's scope.
Your solution is a good one, don't get me wrong. I'm just wondering if there's anything more efficient out there.
gives the name of the subform container control conatining the subform you are currently in.
BINGO! THAT's what I was looking for!
Doesn't work in my case because I need the name of the for the default property of control when the parent active control is not the subform.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.