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

Calculating a table value from values in another table, based on other fields.

17
Currently I have a table, and would like the calculate a field in the table by referencing values from another 3 tables.

i.e. tblData
Expand|Select|Wrap|Line Numbers
  1. Index1, Index2, Index3, Value
  2. 1             2          3
  3. 2             2          2  
  4. 1             3          4
and tblIndex1
Expand|Select|Wrap|Line Numbers
  1. Value    Data
  2. 1            2.5
  3. 2             2
  4. 3           1.5
and tblIndex2
Expand|Select|Wrap|Line Numbers
  1. Value    Data
  2. 1            2.5
  3. 2             2
  4. 3           1.5
etc

so if tblData, field Index1 = 1, then take the Value field from tblIndex1 which is the same as tblData.Index1 and do the same for Index2 and Index 3 and then tblData.Value is a calculation based on those indexes.

i.e. Value = 2.5 * 2 * Index3.Value.

I want to perform this calculation for every ID in tblData.

I've written the following code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdUpdate_Click()
  2.  Dim rcdTesting As DAO.Recordset
  3.  Dim rcdReference As DAO.Recordset
  4.  Dim rcdReference2 As DAO.Recordset
  5.  Dim rcdReference3 As DAO.Recordset
  6.  Dim I As Variant
  7.      Dim Constant As Integer
  8.      Dim Constant2 As Integer
  9.      Dim Constant3 As Integer
  10.  
  11.  
  12.    Set rcdTesting = CurrentDb.OpenRecordset("tblTest2")
  13.    Set rcdReference = CurrentDb.OpenRecordset("tblReference")
  14.    Set rcdReference2 = CurrentDb.OpenRecordset("tblReference2")
  15.    Set rcdReference3 = CurrentDb.OpenRecordset("tblReference3")
  16.  
  17.  With rcdTesting
  18.    For Each I In rcdTesting
  19.    If ![Outing] = rcdReference![Value] Then
  20.    Constant = rcdReference![Result]
  21.    End If
  22.    If ![Lap] = rcdReference2![Value] Then
  23.    Constant2 = rcdReference2![Result]
  24.    End If
  25.    If ![Time] = rcdReference3![Value] Then
  26.    Constant3 = rcdReference3![Result]
  27.    End If
  28.    ![Value] = Constant * Constant2 * Constant3
  29.    Next I
  30.  End With
  31.  
  32. End Sub
But it says I am declaring the I, in the for each statement incorrectly.

Currently the code is written so it updates on button press, but ideally I would like the field up update automatically as each Index value is entered.

Any help would be greatly appreciated.

Thanks,

Zoe
Aug 20 '08 #1
1 2154
NeoPa
32,556 Expert Mod 16PB
Zoe, there are currently too many typos to read your problem without getting confused.

Please take the time to prepare a question that is legible if you would like our experts to take their time to try and help.

-Administrator.
Aug 20 '08 #2

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

Similar topics

7
by: JLM | last post by:
I have a table that has fieldA, fieldB, fieldC. I want fieldC=fieldA-fieldB. simple enough. the next record I want to be able to do the same on the new value of fieldC. I can do this with SAP...
1
by: jlm | last post by:
I have a form which feeds table (TblEmpLeave) of Employee Leave Time (time taken off for Administrative, Annual, Sick, Compensation leave). I have EmpID, LeaveDate, LeaveType, LeaveHours fields on...
2
by: Wayne Aprato | last post by:
I've read most, if not all, of the posts on moving average and still can't find a simple solution to my problem (if a simple solution exists!) I have a table with 2 fields: Hours and Injuries. I...
1
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals....
1
by: Tony Williams | last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value...
3
by: luscus | last post by:
Thanks for all the responses on my first question. Unfortunately the answers I was given were too complicated for my small brain , and neophite condition to understand. So if you could talk down to...
3
by: swinster | last post by:
Hi all, I have not touched access for a very long time and am attempting to help my nephew with his Video Rental Database. This is a simple three-table relationship database comprising a Video...
4
by: zoeb | last post by:
Hi. I have a form which the user enters 2 years worth of data into (one record per year). The aim, is to populate the table this form is based on with 3 more years worth of data (i.e. creating 3...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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
isladogs
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...

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.