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. 5 1875
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.
> 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.
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.
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.
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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
by: Fabio |
last post by:
Hi all,
Whats the real difference between Overloads and Shadows in a Sub????
Thanks in advance,
Fabop
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |