473,405 Members | 2,272 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,405 software developers and data experts.

MS Access Master Detail Form getting error in calculated control

4
I am new in MS Access. I created two simple tables ExpMast and ExpDet which are linked thru PK/FK (1:M) relationship. In order to create a form, I selected the Table ExpMast and then clicked Create->Form which automatically selected all fields from ExpMast and displayed all fields of ExpDet in a block (named Child12 by it) where I can enter multiple records. Now, I believe the block is NOT a subform (which of course I want to avoid as a beginner). At the bottom of the form, I want to display total of all amounts (AMOUNT being the field in ExpDet and the column displayed in the block). I created a control text box and in the Control Source property, typed in "=sum(Amount)" but it is displaying "#Error". I also tried "=sum(child12.amount)" but the same error.
Attached Files
File Type: zip Error.zip (184.8 KB, 127 views)
Aug 16 '09 #1
7 3846
ADezii
8,834 Expert 8TB
@hayat
Expand|Select|Wrap|Line Numbers
  1. =DSum("[Amount]", "ExpDet", "[<Foreign Key>] = " & Forms!ExpMast![ID])
Aug 19 '09 #2
hayat
4
ADezii,
Thank you. It worked. However, when I enter a new record (in the master block) and a few related records in the child block, (OR update any amount in the child block,) the calculated total doesn't show up (or not updated) until I go back to previous records and come back. What I want to do is whenever I enter into the calculated field, the updated total should show up.
Once again thanks for the help.

Hayat
Aug 20 '09 #3
ADezii
8,834 Expert 8TB
@hayat
In the AfterUpdate() Events of both the Master and Child Form, you can force an Update of the Calculated control, namely:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.   Forms![ExpMast]![<Calculated Field Name>] = _
  3.   DSum("[Amount]", "ExpDet", "[<Foreign Key>] = " & Forms!ExpMast![ID])
  4. End Sub
Aug 20 '09 #4
hayat
4
I am sorry, it didn't work. Just to remind, it's just one form (called EXPENSE) having two blocks. I tried the code which is also shown here but the calculated field is not updated.

Private Sub Form_AfterUpdate()
[Forms]![Expense]![CalcTotal] = _
DSum("[Amount]", "ExpDet", "[ExpID] = " & [Forms]![Expense]![ID])
End Sub

I also tried this code in CHILD12 "on exit" event, CalcTotal "on enter" and "Got Focus" events but nothing worked.
Aug 20 '09 #5
ADezii
8,834 Expert 8TB
@hayat
Would you be able to Attach a copy of the Database to a Message?
Aug 20 '09 #6
hayat
4
Please find attached the DB. Thanks.
Attached Files
File Type: zip My Accounts.zip (197.8 KB, 83 views)
Aug 22 '09 #7
ADezii
8,834 Expert 8TB
It appears as though you will need a rather unique solution to this problem. Here is one that will work:
  1. Remove the Control Source from the [CalcTotal] Text Box on the Expense Form.
  2. Set the Timer Interval Property of the Expense Form to 1000 (1 sec.). You can play with this value if you like, but remember it is in milliseconds.
  3. Copy and Paste the following code to the Timer() Event of the Expense Form:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Timer()
    2. If Not Me.NewRecord Then
    3.   Forms!Expense![CalcTotal] = _
    4.   Format(DSum("[Amount]", "ExpDet", "[ExpID] = " & Forms!Expense![ID]), "Currency")
    5. Else
    6.   Forms!Expense![CalcTotal] = Null
    7. End If
    8. End Sub
  4. Disable the Timer() Event whenever appropriate by setting the TimerInterval Property to 0, namely:
    Expand|Select|Wrap|Line Numbers
    1. Me.TimerInterval = 0
  5. Every second, the value in [CalcTotal] will be accurately updated unless you are on a New Record in the Main Form. Once this Record is saved however, the code will be active again.
  6. Download the Attachment to get a better picture of what is going on.
  7. P.S. - The value displayed in [CalcTotal] should be displayed as Currency, which the code allows for.
Attached Files
File Type: zip My Accounts_2.zip (60.4 KB, 119 views)
Aug 23 '09 #8

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

Similar topics

49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
9
by: Colin McGuire | last post by:
Hi, I have an report in Microsoft Access and it displays everything in the table. One column called "DECISION" in the table has either 1,2, or 3 in it. On my report it displays 1, 2, or 3. I want...
0
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that one of the...
1
by: Dman | last post by:
MS Access 2002 - query form control returns funny symbols like I am running an append query on a form. Access is having trouble with the calculated fields and comboboxes. Example – referring...
2
by: Coen | last post by:
Hello, I have a strange performance delay of about 2 sec's in moving to the next row. I use multiple forms with each master-detail table relations. The master-table displays it's table rows in...
7
by: Rich Milburn [MVP] | last post by:
Ok I am not a programmer, I copied some code and very painfully got it working in VB6. I can adjust the volume with waveOutSetVolume on winmm.dll. But I could not seem to be able to figure out how...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
2
by: John | last post by:
Hi I am trying to create a master/detail form. I have my master and details tables dragged onto the dataset. I have also dragged the fields from master table on the form which has created the...
1
by: laura | last post by:
I am new to Access, trying to figure it out on my own. I am trying to create a form to input the same information in 3 different tables. The 3 tables each have a different number as the primary...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
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,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.