By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,377 Members | 3,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,377 IT Pros & Developers. It's quick & easy.

Sub-Form Object ID's

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
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

P: n/a
> 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*********@SeeSig.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*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
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

P: n/a
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_AfterInsert()
If Me.Text1 = "Instance 1" Then
Call Me.Parent.MyFunction(1)
Else
...
End If
End Sub

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

Alternative way to call the parent routine in a form named "Form1":
Call Form_Form1.MyFunction(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*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
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*********@SeeSig.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*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
> 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

P: n/a
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

P: n/a
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*********@SeeSig.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_AfterInsert()
If Me.Text1 = "Instance 1" Then
Call Me.Parent.MyFunction(1)
Else
...
End If
End Sub

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

Alternative way to call the parent routine in a form named "Form1":
Call Form_Form1.MyFunction(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*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
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*********@SeeSig.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*****@verizon.net> wrote in message
news:66**************************@posting.google.c om...
> 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 discussion thread is closed

Replies have been disabled for this discussion.