473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

refresh or requery form from subform change

AccessIdiot
493 256MB
This is driving me nuts.

I have an unbound textbox (txt_SumSize) in my subform that holds the total of a field (Debitage_Size_Quantity)seen in datasheet view (control source =Sum([Debitage_Size_Quantity]).

I have an unbound textbox on my form (txt_SizeTotal) that gets the value from the subform footer when the form loads:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Me.txt_SizeTotal = Me!sbfrm_DEBITAGE_Size.Form![txt_SumSize]
  3. End Sub
  4.  
This works great. But I need the total to refresh or requery when more data is added to the subform.

Nothing I have tried works. Either nothing happens or I get an error. I have tried putting code on the form, on the subform, on the subform footer textbox after update, on change and also on the main form total textbox after update and on change and nothing works.

I am not committed to using the on load function but it was the only code that worked in trying to get the total from the footer to show up on the main form.

Any help appreciated!
Apr 28 '08 #1
7 9256
AccessIdiot
493 256MB
Help? This is the only thing hanging me up (for the moment) and nothing I've searched for works!
Apr 29 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi. I think that using multiple indirect references to unbound controls on forms is a very complicated approach, as you have to keep requerying all the controls to keep them up to date. You don't tell us what the calculation is, or whether it is a sum of values that span more than one row in the subform (that is, a group total).

I would suggest that you either include a calculated field in the underlying query on which your subform is based (the best and simplest solution if the total is a row total) or continue to use an unbound textbox on the main form, but instead of indirectly referring to another textbox use just the one unbound control with a DSUM or whatever domain aggregate function is suitable for your purposes to calculate the total directly. With the unbound textbox you would need to trigger a requery from the after update and after insert events of the subform (at the very least). You might have to requery from the On Current event too - I can't be sure as you haven't told us how the total relates to the records in your main form/subform setup. If you don't use On Current then you would still have to set the initial value of the unbound textbox from the main form's On Load event as at present.

-Stewart
Apr 29 '08 #3
AccessIdiot
493 256MB
I'm sorry, I should have been more detailed. Also, I am totally open to completely redoing how this is done.

I have a form and a subform. The subform is a datasheet view with just two fields: size (a combobox, called Debitage_Size) and quantity (Debitage_Size_Quantity). Then there is the unbound text in the footer that sums the quantity (txt_SumSize). I don't have much experience with unbound fields doing a sum in the footer of a form so I assume it is updating as records are added?

Then there is the unbound field on the form (txt_SizeTotal) that is supposed to grab the total from txt_SumSize and display it.

The code I supplied in my first post is all I have and again, I am not bound to it. It's just the only thing I have tried that actually worked until I hit the wall I'm at now.

Any other suggestions are welcome!
Apr 29 '08 #4
Stewart Ross
2,545 Expert Mod 2GB
OK. As there are only two fields on your subform, is it safe to say it is not linked to the main form in a parent/child (1..many) relationship? If this is the case then the unbound footer textbox is simply performing a running sum of the quantity for all records in the subform recordset.

Forms in datasheet view do not have visible headers and footers, so any controls you place on these areas will work as normal but cannot be seen by the users.

In a test subform I placed an unbound textbox in the footer called txt_SumSize (as in your example) and set its control source to:

=Sum([Debitage_Size_Quantity])

This is indeed updated automatically on each record add or change as you mentioned.

I placed a second unbound textbox on the main form. Instead of trying to update this via code, I simply set its control source property to refer to the field on the subform as shown below. I don't know the name of your main form, so in the example I have used [Debitage Test] for the main form and Debitage for the subform. You would have to replace these with the real names of your main form and subform.

=Forms![Debitage Test].Debitage.Form!txt_SumSize

This tracks the running total in the footer of the subform with no code whatsoever - no event procedures at all. See attached screenshot for an example of the way it operates.

Of course, if a group total is needed the simple Sum in the footer has to change to a DSum or similar as previously discussed.

-Stewart
Attached Images
 
Apr 29 '08 #5
AccessIdiot
493 256MB
That works beautifully, thank you. I had tried something like that before but I must have had the syntax wrong because I got the dreaded Error in the total box on the main form.

A question though - there are only two fields shown on the subform but the underlying table contains a few more, namely an autonumber PK and a FK that is the PK of the table that underlies the main form. And yes, the subform IS linked to the main form in a one to many. So does that affect or change things? Yes the unbound footer textbox should just be a running sum of the quantity in the subform.

Thanks again for your help!
Apr 29 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi again AI. I am glad this approach is working out for you.

The parent/child relationship between the fields of the mainform and subform should take care of the grouping - in effect a WHERE clause is being applied to the subform's recordset automatically to limit its scope to only those records matching the linked parent fields. All being well you should not have to do any more to the unbound textbox in your main form, which should show the correct running total when you select a different grouping in your main form...

Cheers

Stewart
Apr 30 '08 #7
AccessIdiot
493 256MB
Yep, works great, thanks!
Apr 30 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dalan | last post by:
I'm sure there is a workaround for this, but haven't found it yet. I have a mainform with two subforms and after one or both of the subforms are updated, then clicking the Refresh button on the...
6
by: Tim Marshall | last post by:
Here's the situation. A form, frmSetUp, with a subform control called subExplain with a source object form frmSetUpSubDefineSides. The source object is a bound form, displaying a few records, no...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
5
by: Andrew Chanter | last post by:
I have a situation where I am using an unbound dialog form to update data in an Access 2002 split back end / front end scenario. The data update is done via an ADO call (direct to the back end...
2
by: S. van Beek | last post by:
Dear reader, I have a Form with a SubForm. On the MainForm there is a field receiving his content from a group query. If a change or append or delete a record in the SubForm the group...
3
by: ken | last post by:
Hi, I have a main form with a text box and a filter button. I also have a subform in the main form. When I make an entry into the filter text box and click the filter button, I change the query...
4
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays...
1
by: Stinky Pete | last post by:
Hi everyone, I have been updating a file that uses a main form that contains a subform (as a datasheet). The main form really does not do anything on opening except maximizes to the users...
3
by: ApexData | last post by:
COMBOBOX REFRESH DILEMMA ' I have been working for hours trying to figure out how to requery a combobox in a subform, from a Popup form ' that this subform had launched. Basically, I designed...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.