473,804 Members | 3,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sub-Form Object ID's

I'm new to Access. But I've been ooping for about twelve or thirteen
years in another language.

I've got a form with two instances of the same sub-form. It works
quite well, or at least it will, when I find out how the source form
can identify which of its two instances has invoked its after_insert
event handler.

Any ideas on this?

Thanks.
Nov 13 '05 #1
5 1887
From the parent form, it's very easy to tell the difference: the two subform
controls have different names (even though they have the same SourceObject).

From the subform, it's much more difficult: they both have the same
properties, including the same parent. One solution is to place a hidden
text box on the subform. Then use the Load event of the main form to set the
value of the text box in each subform, e.g.:
Me.[Sub1].Form.[Text1] = "Instance 1"
Me.[Sub2].Form.[Text1] = "Instance 2"
That allows you do identify instance from within it. (In practice, you may
need to set a different Default Value for a foreign key in each instance, so
that can be used to achieve the same result.)

Presumably you're okay with passing something back to a proc in the main
form, once you have a way to distinguish the subform instance.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizo n.net> wrote in message
news:66******** *************** ***@posting.goo gle.com...
I'm new to Access. But I've been ooping for about twelve or thirteen
years in another language.

I've got a form with two instances of the same sub-form. It works
quite well, or at least it will, when I find out how the source form
can identify which of its two instances has invoked its after_insert
event handler.

Any ideas on this?

Thanks.

Nov 13 '05 #2
> From the parent form, it's very easy to tell the difference<

But how can I respond to an event such as AfterInsert from the parent
form? I see in the list of properties for the subforms only OnEnter
and OnExit.

I will proceede using the technique you described in your post.

Thanks.
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message news:<41******* *************** *@per-qv1-newsreader-01.iinet.net.au >...
From the parent form, it's very easy to tell the difference: the two subform
controls have different names (even though they have the same SourceObject).

From the subform, it's much more difficult: they both have the same
properties, including the same parent. One solution is to place a hidden
text box on the subform. Then use the Load event of the main form to set the
value of the text box in each subform, e.g.:
Me.[Sub1].Form.[Text1] = "Instance 1"
Me.[Sub2].Form.[Text1] = "Instance 2"
That allows you do identify instance from within it. (In practice, you may
need to set a different Default Value for a foreign key in each instance, so
that can be used to achieve the same result.)

Presumably you're okay with passing something back to a proc in the main
form, once you have a way to distinguish the subform instance.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizo n.net> wrote in message
news:66******** *************** ***@posting.goo gle.com...
I'm new to Access. But I've been ooping for about twelve or thirteen
years in another language.

I've got a form with two instances of the same sub-form. It works
quite well, or at least it will, when I find out how the source form
can identify which of its two instances has invoked its after_insert
event handler.

Any ideas on this?

Thanks.

Nov 13 '05 #3
In the subform's AfterInsert event procedure, you can call a routine all
tell it which subform instance is calling, e.g.

Private Sub Form_AfterInser t()
If Me.Text1 = "Instance 1" Then
Call Me.Parent.MyFun ction(1)
Else
...
End If
End Sub

Then, in the main form's module:
Function MyFunction(intI nstance As Integer)
'do your stuff
End Function

Alternative way to call the parent routine in a form named "Form1":
Call Form_Form1.MyFu nction(1)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Weaver" <we*****@verizo n.net> wrote in message
news:66******** *************** ***@posting.goo gle.com...
From the parent form, it's very easy to tell the difference<


But how can I respond to an event such as AfterInsert from the parent
form? I see in the list of properties for the subforms only OnEnter
and OnExit.

I will proceede using the technique you described in your post.

Thanks.
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message
news:<41******* *************** *@per-qv1-newsreader-01.iinet.net.au >...
From the parent form, it's very easy to tell the difference: the two
subform
controls have different names (even though they have the same
SourceObject).

From the subform, it's much more difficult: they both have the same
properties, including the same parent. One solution is to place a hidden
text box on the subform. Then use the Load event of the main form to set
the
value of the text box in each subform, e.g.:
Me.[Sub1].Form.[Text1] = "Instance 1"
Me.[Sub2].Form.[Text1] = "Instance 2"
That allows you do identify instance from within it. (In practice, you
may
need to set a different Default Value for a foreign key in each instance,
so
that can be used to achieve the same result.)

Presumably you're okay with passing something back to a proc in the main
form, once you have a way to distinguish the subform instance.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizo n.net> wrote in message
news:66******** *************** ***@posting.goo gle.com...
> I'm new to Access. But I've been ooping for about twelve or thirteen
> years in another language.
>
> I've got a form with two instances of the same sub-form. It works
> quite well, or at least it will, when I find out how the source form
> can identify which of its two instances has invoked its after_insert
> event handler.
>
> Any ideas on this?
>
> Thanks.

Nov 13 '05 #4
Hi Gents,

What about responding to the parent forms events by delcaring the
parent form as a module level variable with events in the subforms?

eg Private WithEvents mfrm as Form

This way you have purely event driven code in which the parent form
doesn't need to know anything about the subforms.

Haven't tested it but can't see why it wouldn't work...

Regards,

Peter
But how can I respond to an event such as AfterInsert from the parent
form? I see in the list of properties for the subforms only OnEnter
and OnExit.

I will proceede using the technique you described in your post.

Thanks.

Nov 13 '05 #5
Thanks Allen. This is a good technique to know about.

As it turns out, this only reason I needed to know which instance
invoked the event was to know which of two values to use in processing
the data. I just put that value in the forms hidden field. So
instead of doing the
if ... then ... else
I just set ThisYear to the appropriate value ahead of time then stated
Me.Year = ThisYear
in the event handler.

Thanks again.
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message news:<41******* *************** *@per-qv1-newsreader-01.iinet.net.au >...
In the subform's AfterInsert event procedure, you can call a routine all
tell it which subform instance is calling, e.g.

Private Sub Form_AfterInser t()
If Me.Text1 = "Instance 1" Then
Call Me.Parent.MyFun ction(1)
Else
...
End If
End Sub

Then, in the main form's module:
Function MyFunction(intI nstance As Integer)
'do your stuff
End Function

Alternative way to call the parent routine in a form named "Form1":
Call Form_Form1.MyFu nction(1)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Weaver" <we*****@verizo n.net> wrote in message
news:66******** *************** ***@posting.goo gle.com...
From the parent form, it's very easy to tell the difference<


But how can I respond to an event such as AfterInsert from the parent
form? I see in the list of properties for the subforms only OnEnter
and OnExit.

I will proceede using the technique you described in your post.

Thanks.
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message
news:<41******* *************** *@per-qv1-newsreader-01.iinet.net.au >...
From the parent form, it's very easy to tell the difference: the two
subform
controls have different names (even though they have the same
SourceObject).

From the subform, it's much more difficult: they both have the same
properties, including the same parent. One solution is to place a hidden
text box on the subform. Then use the Load event of the main form to set
the
value of the text box in each subform, e.g.:
Me.[Sub1].Form.[Text1] = "Instance 1"
Me.[Sub2].Form.[Text1] = "Instance 2"
That allows you do identify instance from within it. (In practice, you
may
need to set a different Default Value for a foreign key in each instance,
so
that can be used to achieve the same result.)

Presumably you're okay with passing something back to a proc in the main
form, once you have a way to distinguish the subform instance.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Weaver" <we*****@verizo n.net> wrote in message
news:66******** *************** ***@posting.goo gle.com...
> I'm new to Access. But I've been ooping for about twelve or thirteen
> years in another language.
>
> I've got a form with two instances of the same sub-form. It works
> quite well, or at least it will, when I find out how the source form
> can identify which of its two instances has invoked its after_insert
> event handler.
>
> Any ideas on this?
>
> Thanks.

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4080
by: Terry | last post by:
The following code (VB6) automatically sets ticks or null values for Check Boxes: 'Pass' and/or 'Resit', depending on the data entered in the 'ModuleID' and 'Mark' Text Boxes. 'ModuleID' is a Text Box which records the module number of the exam. Module 1 has a pass mark of 27 and modules 2-7 have a pass mark of 24. Private Sub Mark_AfterUpdate() Dim intPassMark As Integer
6
6559
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query works fine, but passing the resulting recordset back to the sub's caller is not working out.
3
2473
by: Kathy Burke | last post by:
Hi, I'm tired, so this question may be silly. I have a fairly long sub procedure. Based on one condition, I load another sub with the following: If Session("GRN") = "complete" Then txtScan.Text = Session("SN") txtScan_TextChanged(sender, e) Session("GRN") = "" Exit Sub End If
7
7777
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because ASP.NET always sets the Session cookie domain to the full domain (e.g. "www.mydomain.com") instead of the parent domain (e.g. "mydomain.com") The problem with this is when the visitor goes to a different sub-domain (e.g. "search.mydomain.com"),...
3
1590
by: Fabio | last post by:
Hi all, Whats the real difference between Overloads and Shadows in a Sub???? Thanks in advance, Fabop
12
7097
by: Ron | last post by:
Greetings, I am trying to understand the rational for Raising Events instead of just calling a sub. Could someone explain the difference between the following 2 scenarios? Why would I want to raise an event instead of just calling the sub? Scenario1 -- Using Events ------------------------------------------------------ Public Class Form1
5
1909
by: Sharon | last post by:
Hi all. To prevent access to a sub system internal types, is it necessary to create the sub system in a different project, and use the internal access level? Or is there another way that will enable the creation of several sub systems in the same project? Thanks, Sharon.
5
9019
by: Jay | last post by:
In a sub procedure how do I recall/restart the sub and maintain the position in a loop? Eg (this doesnt work how I need it to work)... sub Get_Language() 'code here to prompt the user to do something '...
6
1712
by: Bob | last post by:
Hi, I found this code here below (about cartitems and shoppingcart) and I have two questions about sub New(). In the first class CartItem, there is two times sub New(): Public Sub New() End Sub and
8
2812
by: Poudda | last post by:
Hey there, I'm new to VB and I'm having difficulty transferring a variable from one sub to the next. All I want to do here is ask for a variable (in this case, value is x) from a sub (subAsk), use it in my main sub (which manipulates it) and then reproduce the original value in a third sub (subAns). It only half works, and I've been all over the place looking for answers. Below is the code for what I'm trying to do (I'm in VBA for exel, but...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.