Link parent to child fields (1 Viewer)

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
Hey there, isit possible to link two or more field in the parent to child fields on form? If yes, how can i do that?

I want to achieve like when i click on the line that contain white colour on the master subform, the details subform should only display the data that contain white
 

Attachments

  • Database411 (2).zip
    95.3 KB · Views: 36
  • Untitled.png
    Untitled.png
    35.4 KB · Views: 84
Last edited:

bob fitz

AWF VIP
Local time
Today, 00:53
Joined
May 23, 2011
Messages
4,719
Is this what you require.

The text box(txtColour) on the main form(Form1) should be hidden. It uses a reference to the "Color" on the sub form called "Master". The query for sub form called "Details" references the text box(txtColour) on the main form(Form1) as criteria to restrict the records shown.
 

Attachments

  • Database411Bob01.zip
    88.6 KB · Views: 42
Last edited:

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
Is this what you require.

The text box(txtColour) on the main form(Form1) should be hidden. It uses a reference to the "Color" on the sub form called "Master". The query for sub form called "Details" references the text box(txtColour) on the main form(Form1) as criteria to restrict the records shown.

Thank you for your help! It solve my issue. After trying out this, i use it on tthe other database which works perfectly fine but how can i remove an extra line of colour which does not have any value?
 

Attachments

  • Data.png
    Data.png
    6.1 KB · Views: 41

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
Can you post a db which shows the problem

I am sorry, i cannot post the db here as it contain confidential information. I am facing issue with an extra line of colour appearing which does not contain any information. Based on the image i attached, i have box the extra line of colour which should not appear as it contain no data
 

Attachments

  • error.png
    error.png
    6.2 KB · Views: 38

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
Is this what you require.

The text box(txtColour) on the main form(Form1) should be hidden. It uses a reference to the "Color" on the sub form called "Master". The query for sub form called "Details" references the text box(txtColour) on the main form(Form1) as criteria to restrict the records shown.

Do you know how can save the data in the "detail" subform, and it will sum up the calculation part in the "master" subfrom?
 

bob fitz

AWF VIP
Local time
Today, 00:53
Joined
May 23, 2011
Messages
4,719
Put a text box in the subject forms footer section to sum the calculation. This text box can then be referenced from another text box on the main former or the other sub former to show it's value

PS
Did you get the private message that I sent you?
 

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
Put a text box in the subject forms footer section to sum the calculation. This text box can then be referenced from another text box on the main former or the other sub former to show it's value

PS
Did you get the private message that I sent you?

hi, but what if i retrieve the data from "Master" subform and save in my table, will the above method still helps in breaking down the calculation in the "detail" subform?

I did not receive the private message
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:53
Joined
Feb 19, 2002
Messages
43,219
Luzz,
Look to the left of the row you are questioning. It has an asterisk (*). That is the way Access indicates a new, empty row. If you don't use the form to add records, change the AllowAdditions property of the form to No. That will remove the "new" record row. It will also remove the ability to add new records. You can have both but it will require code that can be used to toggle the AllowAdditions property.
 

bob fitz

AWF VIP
Local time
Today, 00:53
Joined
May 23, 2011
Messages
4,719
hi, but what if i retrieve the data from "Master" subform and save in my table, wil............
Not usually a good thing to save calculations to a table. Normally better to do the calculation whenever and wherever it is needed.
 

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
Luzz,
Look to the left of the row you are questioning. It has an asterisk (*). That is the way Access indicates a new, empty row. If you don't use the form to add records, change the AllowAdditions property of the form to No. That will remove the "new" record row. It will also remove the ability to add new records. You can have both but it will require code that can be used to toggle the AllowAdditions property.

Thank you! It has been solved!!
 

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
Not usually a good thing to save calculations to a table. Normally better to do the calculation whenever and wherever it is needed.

Hmm, I am actually doing calculation on the form before saving it to the table. What other suggestion do you have?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:53
Joined
Feb 19, 2002
Messages
43,219
In most cases, calculations should be done in queries. That way if any of the operand values change, the result changes. A good example of what not to store is AGE.

You can calculate Age in a query so if you want to select only people who are between 18 and 26, that is easy enough. However if you calculate Age and store it. Tomorrow, some of your records will be incorrect because anyone who had a birthday today will be one year older tomorrow. The situation is less obvious in other cases but the rules of normalization warn against storing any data that is not 100% dependent on the primary key. So Age is dependent on two things - DOB and today's date. DOB is dependent on the person but today's date changes every day and so you can't store it.

Another situation is if you have a startDate and EndDate in the same record. You can always calculate the difference in a query. If you store the difference in the record, it wastes space and you have to be absolutely certain that any place either date could be changed will also force the recalculation of the difference. This leaves a gaping hole and if the programmer is even a little sloppy or a new person takes over the app and doesn't recognize the danger, he may create a new procedure and not understand the ramifications of not forcing the calculation. It is your fiduciary responsibility to ensure that data is as accurate as you can make it so don't store data that can be easily calculated and will always be accurate if calculated but may be out dated if stored.

When we create a data warehouse as many large companies do for reporting. The data warehouse is always AS OF some date and no individual records ever get changed. The complete set of data is replaced or updated every day, week, month - whatever but never in between. Given that, it is quite OK to store calculated values and doing so simplifies the user's work and minimizes the knowledge he needs to create custom reports.
 

luzz

Registered User.
Local time
Yesterday, 16:53
Joined
Aug 23, 2017
Messages
346
In most cases, calculations should be done in queries. That way if any of the operand values change, the result changes. A good example of what not to store is AGE.

You can calculate Age in a query so if you want to select only people who are between 18 and 26, that is easy enough. However if you calculate Age and store it. Tomorrow, some of your records will be incorrect because anyone who had a birthday today will be one year older tomorrow. The situation is less obvious in other cases but the rules of normalization warn against storing any data that is not 100% dependent on the primary key. So Age is dependent on two things - DOB and today's date. DOB is dependent on the person but today's date changes every day and so you can't store it.

Another situation is if you have a startDate and EndDate in the same record. You can always calculate the difference in a query. If you store the difference in the record, it wastes space and you have to be absolutely certain that any place either date could be changed will also force the recalculation of the difference. This leaves a gaping hole and if the programmer is even a little sloppy or a new person takes over the app and doesn't recognize the danger, he may create a new procedure and not understand the ramifications of not forcing the calculation. It is your fiduciary responsibility to ensure that data is as accurate as you can make it so don't store data that can be easily calculated and will always be accurate if calculated but may be out dated if stored.

When we create a data warehouse as many large companies do for reporting. The data warehouse is always AS OF some date and no individual records ever get changed. The complete set of data is replaced or updated every day, week, month - whatever but never in between. Given that, it is quite OK to store calculated values and doing so simplifies the user's work and minimizes the knowledge he needs to create custom reports.

Hmm, for my calculation part is a bit complicated and confusing. Firstly, i will need to convert pounds to KG before doing the calculation for the gross weight. The gross weight calculation is determined by a few factors such as the fabrication, reference, and sample requirement, thus there will be difference calculation for the different type of fabrication and reference. Lastly, with the gross weight, i will need to calculate the loss for this fabrication. So is it still possible to use a query to automate the calculation for this?
 

isladogs

MVP / VIP
Local time
Today, 00:53
Joined
Jan 14, 2017
Messages
18,209
I would use a function which performs each calculation in turn
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:53
Joined
Feb 19, 2002
Messages
43,219
I agree with ridders, If the calculation is too complex for you to want to code it in the query, use a function.

Also, if you always have to convert pounds to Kilos, why not store as kilos?
 

Users who are viewing this thread

Top Bottom