Hi - I have a form called mainForm that has a subform called subForm. The subform has a numeric field called subCost. There are many subForm records for every mainForm record. On the main form, there is a field called mainCost.
Whenever someone makes a change to the subCost field, I want to populate the mainCost field with the sum of the subCost values. The mainForm and the subForm are joined by mainID = subID.
Here is my lame attempt at writing this myself (on the After Update event of the subCost field). - mainCost = "(SELECT Sum([subCost]) From subForm WHERE [subForm.subID] = [mainForm.mainID)"
Any help you can provide would be greatly appreciated.
Thanks in advance,
Bill
Aug 31 '09
24 6490
I'm good with this. I just can't figure out the part about assigning the value on the VBA side for the Calculated Total. I don't know how to make that happened and have tried a variety of things...
you just need to write code probably on the Form_Activate() . You need to write some code along the lines of: -
Private Sub Form_Activate()
-
Me.Order_Cost_Subtotal.Value = [enter the code to retrieve the value from the subform]
-
End If
-
I am here to help, but I also would like you to get the hang of this without me giving you the answer outright.
I can answer any questions you have to the best of my ability. Don't hesitate to ask.
-AJ
Why the Activate event? I've not used that, but it says this runs when the form opens and becomes the active form. Which means it won't run when I move from record to record.
Even if the activate worked when moving from the sub-form to the regular form, I don't want the value on the regular form to wait that long. I want to update it from while I'm still inside the subform.
Why can't this be done on the After Update event on the Order_Item_Cost field?
And I've tried (on the After Update event of the Order_Item_Cost field)
Me.Parent.Order _Cost_Subtotal. Value = sub_Order_Item_ Extended_Subtot al (which is what I called the sum field in the footer of the subform)
I've also tried a bunch of other variations and the best I can get it to do is to change to zero, which is odd but seems like my syntax is correct.
for future reference you need to use the [code] Tags when posting code, the button looks like a "#".
Now try this: -
Me.Parent.Order_Cost_Subtotal.Value = me.sub_Order_Item_Extended_Subtotal.value
-
Me.Parent.Order_Cost_Subtotal.Requery
-
-AJ
-
Private Sub Order_Item_Cost_AfterUpdate()
-
-
Order_Item_Extended_Cost = Order_Item_Quantity * Order_Item_Cost
-
Me.sum_on_sub_form.Requery
-
Me.Parent.sum_on_main_form.Requery
-
-
End Sub
-
-
Private Sub Order_Item_Cost_LostFocus()
-
-
Me.Parent.Order_Cost_Subtotal.Value = Me.sum_on_sub_form.Value
-
-
End Sub
-
This is as close as I've gotten it. I changed the sum field names so I could keep track of them better. The result here is that if you change the amount and hit tab, the cursor stays in the amount field and the two sum fields change (the one on the main form and the one on the subform). Then tab again and the subtotal field on the main form changes as I desired. I have no idea why the first tab doesn't leave the field.
Putting the -
Me.Parent.Order_Cost_Subtotal.Value = Me.sum_on_sub_form.Value
-
in the After Update instead of the Lost Focus does nothing. It just zeros out the field on the main form.
Adding the requery you suggested in the last post did nothing at all regardless of where the -
Me.Parent.Order_Cost_Subtotal.Value = Me.sum_on_sub_form.Value
-
was located.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: sao |
last post by:
I am currently using Access 2000.
In my table it is the following fields that are set up:
1 - Staff Name
2 - Department
This table is already populated with 100+ records (staff along with
department.)
|
by: Lauren Quantrell |
last post by:
I'm using SQL Server backend on an Access 2K front end.
I populate a subform:
Forms!myForm.myChild.Form.RecordSource = "myStoredProcedureName"
On that form is a control where the controlsource is "=
Count()"
that shows the user the number of records.
What I'm doing now is populating the subform, using the
RecordsetClone.RecordCount of the subform to determine if any records
were returned, and if not, opening a message box telling the...
|
by: Michelle |
last post by:
Hi all
I have used knowledge base article 112747 to improve my subforms
performance. I am using Access 97.
I have a main form where i put an extra textbox which concatenated
TeamID WeekNum Weekday, ie value might be 15Monday. I then put in a
field in my query behind my subform which held the same info and used
these fields to link the mainform to the subform.
|
by: Lyn |
last post by:
Hi,
I am working on a genealogy form. The only table (so far) lists everybody
in the family, one record per person. Each record has an autonum ID.
The parent form (frmMainForm) displays the data in each record, which
includes the ID of the father and the mother (who also have records in the
table). One record per form.
I have a Tab Control in the form, and in one of the tabs I have a subform
(sfmSiblings) in which I wish to list...
|
by: tconway |
last post by:
I have an Access program that displays Customer data into a form and
OrderID data into a subform. The totals in the Subform are based on
calculated fields, i.e. the Total Amount field Calculates the
following: =*
The Subform Order fields are pulled from a Query along with each
calculated Total. They are displyed in a DataSheet View.
This works fine on my developement environment which includes a server
set up just as our client has. ...
| |
by: Ecohouse |
last post by:
I have a main form with two subforms. The first subform has the child
link to the main form identity key.
subform1 - Master Field: SK
Child Field: TrainingMasterSK
The second subform has a master-child link to the first subform.
subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK
Child Field: TrainingModuleTopicSK
|
by: Don Do |
last post by:
Help
I built a form/subform/subsubform setup using the access forms
wizard. I have a table1 = parent, table2 = child, table3 =
(grandchild?). There will be multiple records in table2 that tie to
table1, and multiple records in table 3 that tie to table2. Both on
"1 to many" joins.
Each of the forms are bound to the fields in the respective tables.
The subform & subsubform are datasheet view. When I enter any data, I
|
by: Mary |
last post by:
I'll pulling my hair out on this one and would be so appreciative of
any help.
I am creating a data entry form to enter results of a student survey.
There are 40 questions on the survey. The first 7 have to do with
respondent information like grade, class and age. I have those in a
table with a PK of RespondentId, which is autonumbered. Questions 8-40
all have the same format. For these questions I have a table set up
with the...
|
by: GODSPEEDELECTRONICS |
last post by:
My database is simple. It has a table that tracks customers, with they're name, address, etc.
I have a price list table that contains "iteminstall" , "price", and "qty"
and I have a payment table that trackes date, and payment amount.
I have a subform, with the field (textbox) "price." I have it auto populate when I type in something under (combobox) "iteminstall". This is a recent addition. I used to have to type it manually.
In...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |