473,789 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

17 New Member
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 2179
NeoPa
32,579 Recognized Expert Moderator MVP
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
2182
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 ABAP/4, but have never done this using Access. I'm sure this can be done, but not sure how to go about it. thanks in advance, jlm
1
2380
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 this form. Any employee can have multiple entries in the table (key fields are EmpID and LeaveID) for multiple dates (John Doe can take 3 days annual leave, then take 3 days sick leave in any given month. I have a BeginningBalance of hours that...
2
13608
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 have a query based on this table which shows these 2 fields and calculates a third field: Frequency Rate, based on a formula which uses the Hours and Injuries fields. Is there a simple way of A: using yet another calculated field in the query...
1
2510
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. first, let me say that this is a really long post. i wasn't sure how much information/ background to provide, so i thought more was better than less. i tried to delineate certain areas so that it would be easy to peruse my posting and find...
1
4310
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 of txtmonth and the value of txtvalue in another value of txtmonth and the percentage increase . For example if I have the value 1000 in 30/03/03 and the value 1100 in 30/03/04 How do I calculate the difference as 100 and the increase as 10%. I...
3
2723
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 me and write in easier terms I would be very gratefull to all you access wizards! Here is my problem. I have a table with maybe 10 fields, It is used to imput information taken over the phone to solve patient problems in our Spanish...
3
1788
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 Table, Customer Table and Rental Table. We have a simple form whose source is set to the Rental Table. We want to calculate the fine on a late video using the number of days the video is late (from Rental Table) multiplied by the cost of the video...
4
4850
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 new records), based on a percentage increase on the previous year. This form is based directly on a table called tblBudgetShareProj. So far I have the following code but I am COMPLETELY new to VB and I'm very aware of how incomplete it is. I have a...
275
12408
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
9506
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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, 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...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
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 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...
0
9016
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, 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...
0
6761
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();...
0
5415
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...
1
4089
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
bsmnconsultancy
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...

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.