Get the information from subform to populate a table entry in the main form (1 Viewer)

Local time
Today, 14:34
Joined
Feb 27, 2022
Messages
49
Hi all,

I have a form with a couple of subforms on it. These subforms have a summed total amount which I want to populate an entry in the main forms table. For example, let's say each subform on the main form contained a summed total for Widget A amount (on subform 1), Widget B amount (subform 2) and Widget C amount (subform 3)- let's say $15, $25 and $50 respectively.

If on the table running the main form I have something like "Widget A Total", "Widget B Total", "Widget C Total", how would I get the totals from the subforms to populate the form's main table respective entries with $15, $25 and $50?

I tried something like: Me.WidgetATotal = Me.WidgetAAmount and put that with the "On Change" Event. Tried it, did nothing.

Could anyone please tell me what I'm doing wrong or a better way to go about it?

Thank you.
 

June7

AWF VIP
Local time
Yesterday, 21:04
Joined
Mar 9, 2014
Messages
5,466
Why would you want to save aggregate data? This can be calculated when needed.
 
Local time
Today, 14:34
Joined
Feb 27, 2022
Messages
49
Yes I understand that. But some of the subforms are like calculators, which don't store a value for each record.
 

June7

AWF VIP
Local time
Yesterday, 21:04
Joined
Mar 9, 2014
Messages
5,466
Code behind subform can set value into main form field/control.
Perhaps you should provide db for analysis.
 
Local time
Today, 14:34
Joined
Feb 27, 2022
Messages
49
Sure thing.

I put together a quick example database which shows a sample of one of the subforms.

If you load the frmMainTable, you will see a subform which requires parameters to filter and get the respective cost. For example, if you select, Box type = Non Standard, Box Size = Small and enter 1 for each of the dimensions and weight, (select the "Filter Table" button) and you will see the "TOTAL COST" amount change.

What I want is the TOTAL COST value to also be put into the "Price to Purchase" field in the main form and have a table entry. (table entry field = "Price")
 

Attachments

  • boxSizeTest.zip
    587.7 KB · Views: 279

June7

AWF VIP
Local time
Yesterday, 21:04
Joined
Mar 9, 2014
Messages
5,466
Data structure makes no sense. tblMainTable has only ID and Price fields and no relationship to other table.

What is purpose of db? What are you trying to accomplish with this design?

However, try this as last line of Command32 code.
Me.Parent.Price = Me.Price

Suggest you set both Price textboxes as Locked Yes and TabStop No.

Advise to give controls better names than the Access assigned defaults.
 
Local time
Today, 14:34
Joined
Feb 27, 2022
Messages
49
Thanks June7.

I know there is no relationship- the subform is there to find a respective filtered record from a 'reference' table to apply to the record as circumstances warrant. The database will be used by myself to cost items- so I'm not looking for something awesome, but rather something just functional.

I tried your suggestions and it worked- thank you.

The control names are default as that is just a quick new sample database of what I was trying to communicate- so I didn't bother changing names and such.

Appreciate your time, help and suggestions. :)
 

Users who are viewing this thread

Top Bottom