473,804 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

One sub form linked to another

I have a basic form. On it are two sub forms. The top sub form has a
list of records. When a user clicks on a new row within the top sub
form. I want the RecordSource of the bottom sub form to change
according to some data in the row of the top sub form.

Main Form Name: Form1
Top Sub Form Name: frmT1_Datasheet
Bottom Sub Form Name: frmT2_Datasheet

The code in frmT1_Datasheet is:

Private Sub Form_Current()
[Forms]![Form1]![frmT2_Datasheet].Form.RecordSou rce = _
"SELECT * FROM tblT2 WHERE ID = " & Me![Number]
End Sub

IT DOES WORK! HOWEVER...it does not work when first loading Form1. I
get the message, "Run-time error '2455': You entered an expression
that has an invalid reference to the property Form/Report".

I'm guessing that it is because frmT2_Datasheet is not loaded yet.
After it is loaded it works fine.

Is there another way to do this? Or is there a work around?
Nov 13 '05 #1
4 4690
Your description leads me to believe that the RecordSource of the Form
embedded in the first Subform Control is related one-to-many to the data in
the main Form, and that the RecordSource of the Form embedded in the second
Subform Control is related one-to-many to the data in the Form embedded in
the first Subform Control. An appropriate approach to handling such data
would be to embed the second Subform Control in the form embedded in the
first Subform Control, rather than embedding it in the main Form. That will
likely avoid the error you describe.

The expectation would be that the Fields listed in LinkMasterField s are in
the RecordSource of the main Form and the LinkChildFields are in the
RecordSource of the Form embedded in the Subform Control. However, you can
use a reference to a Control -- perhaps you could use this rather than
trying to set the RecordSource of the Form embedded in the Subform Control?

Larry Linson
Microsoft Access MVP

"Paul" <pw****@hotmail .com> wrote in message
news:b8******** *************** ***@posting.goo gle.com...
I have a basic form. On it are two sub forms. The top sub form has a
list of records. When a user clicks on a new row within the top sub
form. I want the RecordSource of the bottom sub form to change
according to some data in the row of the top sub form.

Main Form Name: Form1
Top Sub Form Name: frmT1_Datasheet
Bottom Sub Form Name: frmT2_Datasheet

The code in frmT1_Datasheet is:

Private Sub Form_Current()
[Forms]![Form1]![frmT2_Datasheet].Form.RecordSou rce = _
"SELECT * FROM tblT2 WHERE ID = " & Me![Number]
End Sub

IT DOES WORK! HOWEVER...it does not work when first loading Form1. I
get the message, "Run-time error '2455': You entered an expression
that has an invalid reference to the property Form/Report".

I'm guessing that it is because frmT2_Datasheet is not loaded yet.
After it is loaded it works fine.

Is there another way to do this? Or is there a work around?

Nov 13 '05 #2
Thanks for your response Larry. I don't completely understand your
post. However, I have a few comments.

First of all, the main form (Form1) has nothing to do with the two sub
forms. It is just a holder for the two sub forms. So there is no
linkage between Form1 and the two sub forms.

Second, both sub forms (frmT1_Datashee t and frmT2_Datasheet ) are
datasheet forms. So I cannot embed T2 into T1; unless you meant into
the header or footer of the form. I would prefer not to do that. It
doesn't seem very clean.

With that in mind, would what you said earlier still work?
Nov 13 '05 #3
pw****@hotmail. com (Paul) wrote in
news:b8******** *************** ***@posting.goo gle.com:
I have a basic form. On it are two sub forms. The top sub
form has a list of records. When a user clicks on a new row
within the top sub form. I want the RecordSource of the
bottom sub form to change according to some data in the row of
the top sub form.

Main Form Name: Form1
Top Sub Form Name: frmT1_Datasheet
Bottom Sub Form Name: frmT2_Datasheet

The code in frmT1_Datasheet is:

Private Sub Form_Current()
[Forms]![Form1]![frmT2_Datasheet].Form.RecordSou rce = _
"SELECT * FROM tblT2 WHERE ID = " &
Me![Number]
End Sub

IT DOES WORK! HOWEVER...it does not work when first loading
Form1. I get the message, "Run-time error '2455': You entered
an expression that has an invalid reference to the property
Form/Report".

I'm guessing that it is because frmT2_Datasheet is not loaded
yet. After it is loaded it works fine.

Is there another way to do this? Or is there a work around?


Yes there is. Create a hidden, unbound textbox on Form1. Let's
call it txtLinker,
In frmT1_Datasheet . put the following code in the form's current
event.

Me.parent.textl inker.value = me.number

Now you can setup the rowsource of frmT2_Datasheet to be SELECT *
FROM tblT2. Just make the link parent fields property to the
txtLinker created above.

--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #4
Thanks Bob! I got it to work.
Nov 13 '05 #5

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

Similar topics

4
19818
by: intl04 | last post by:
How do I create a data input form in Access that is external to the Access database to which it's connected (if that's possible, which I believe it is)? For example, if someone clicks on an Access file icon on a computer desktop, it will open up a data entry form (that was created in Access). That way, the people who enter the data won't have direct access to the database at any point. I've seen that this can be done, but I don't know...
9
3341
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text field called . It gets populated based on what the user selects in a field on the sub form (code in the AfterUpdate Event). Here's the issue. If the user deletes a subform record. The field on the main form shows null even if there is a value in the preceding subform record. What I'd like it to do is immediately refresh to
3
3817
by: intl04 | last post by:
Is it possible to create a Word form as the data entry form for an Access database? I didn't see any reference to this possibility in my Access books, so I'm sorry if this is a question that is rather off-the-wall. I was asked to ask this question, to see if a Word form can be linked to an Access database and then emailed to various end-users for them to complete task requests using this form.
4
3210
by: glenhong | last post by:
Hi I need some help here. I am running Access 2003. I have an Access DB linked (Front-end) to another Access DB (Back-end). I have a Form which has a third party grid on it. The grid is populated by creating an adodb recordset and assigning the recordset to the grid.
0
1320
by: weezles | last post by:
hi I'm having trouble with using a linked form instead of a sub form on a 1 to many relationship. Then linked form can be accessed from various other forms. When it opens the linked form, if there are no records the clientID is 0. I tried the following code behind the button to open the linked form: stLinkCriteria = "=" & Me!
5
3935
by: ortaias | last post by:
I have a form which calls up a second form for purposes of data entry. When closing the data entry form and returning to the main form, things don't work as expected. When I return to the main form, I trigger the on acitvate event to run a macro. I can use the Dlookup function to update my fields, which is OK. However, I intitially tried to use the Repaint Object command to repaint the form. That did not work. Though I solved the...
1
1973
by: Doll | last post by:
I need some help please. I need to show data as disabled but visible on 1 of my forms that is linked up to another table. For example: I have 2 forms and 2 tables. Form A is linked to table A. Form B is linked to Table B. The cost field is from the componentcost table and linked to on Form b, but I want it also to show up on Form A but form A is linked to the inventory table. I only need it to show up on Form A for viewing purposes...
3
2268
by: cyber0ne | last post by:
Probably another easy question... I have two data tables. One holds the main data, the other holds additional data on a many-to-one relationship with the main data. Using the forms wizard, my goal was to create a form where you enter the main record, then a button brings up the sub-form where you enter as many of the additional info records as needed, all linking back to the main record. However, the forms don't seem linked in that...
3
1714
by: john | last post by:
I have a form with Members and in that form a subform with Transactions. Those are linked (on banknr) 1xM which I've set in the database relations. Now I would like to copy the form and modify it. I would like Transactions to become the main table in the form so I can filter all new Transactions (seems like a Mx1 relation). When new transactions have arrived I would like to go through them one by one, and make some changes in the linked...
11
4098
beacon
by: beacon | last post by:
Hi everybody, I created a database that links one table from an ODBC data source. I saved my password and UID to the data source so neither myself nor anyone else would have to login each time (that's just bonus background info). I take this table, which is read-only, and run an APPEND query that adds new items from the table into another table I created (that has two additional fields that will be updated by the user via a form). I also...
0
9594
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
10595
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
10089
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
9171
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...
1
7634
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.