473,657 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate 2 records based on a comparison of data

3 New Member
I have an Access 2000 database in which I need to update both records in a pairing, based on the difference in the value of a quantity field.

This is an example of the pertinent data in the table.

Pairing Individual Quantity Status
AB A 15
AB B 13

CD C 13
CD D 15

EF E 14
EF F 14

There will always be 2 individuals per pairing.
Each individual will have a value in the quantity field.

I need to populate a status field for both individuals, based on the difference between the quantity values of each of the individuals in the pairing. The actual difference is not relevant for this status code, just which individual’s quantity is More than, Less than or Equal to the other individual’s quantity. The codes could be +1, -1 or 0 if I need to us them in other calculations. The results I need would be similar to this:

Pairing Individual Quantity Status
AB A 15 M or +1
AB B 13 L or -1

CD C 13 L or -1
CD D 15 M or +1

EF E 14 E or 0
EF F 14 E or 0

How can I do this in Access 2000?

Thanks,
Feb 26 '07 #1
10 1991
ADezii
8,834 Recognized Expert Expert
I have an Access 2000 database in which I need to update both records in a pairing, based on the difference in the value of a quantity field.

This is an example of the pertinent data in the table.

Pairing Individual Quantity Status
AB A 15
AB B 13

CD C 13
CD D 15

EF E 14
EF F 14

There will always be 2 individuals per pairing.
Each individual will have a value in the quantity field.

I need to populate a status field for both individuals, based on the difference between the quantity values of each of the individuals in the pairing. The actual difference is not relevant for this status code, just which individual’s quantity is More than, Less than or Equal to the other individual’s quantity. The codes could be +1, -1 or 0 if I need to us them in other calculations. The results I need would be similar to this:

Pairing Individual Quantity Status
AB A 15 M or +1
AB B 13 L or -1

CD C 13 L or -1
CD D 15 M or +1

EF E 14 E or 0
EF F 14 E or 0

How can I do this in Access 2000?

Thanks,
Create a Query consisting of the [Pairing], [Individual], and [Quantity] Fields. Create a Calculated Field called Status which will call the fReturnStatus2([Quantity]) Function and return the appropriate return value for each matching pair. All the code has been centralized within the Function for demo purposes only. This is not the most efficient way to arrive at the answer especially with the Arrays being populated for each Record. Good Luck.
Expand|Select|Wrap|Line Numbers
  1. Calculated Field ==> Status: fReturnStatus2([Quantity])
Expand|Select|Wrap|Line Numbers
  1. Public Function fReturnStatus2(MyQuantity As Integer)
  2. Dim MyDB As Database, MyRS As Recordset
  3. Static intRecCounter As Integer
  4. Dim intNumberOfRecords As Integer
  5. Dim T As Integer
  6.  
  7. intRecCounter = intRecCounter + 1   'Current Record Number
  8. Set MyDB = CurrentDb()
  9. Set MyRS = MyDB.OpenRecordset("tblPairings", dbOpenDynaset)
  10.  
  11. MyRS.MoveLast: MyRS.MoveFirst
  12.  
  13. intNumberOfRecords = MyRS.RecordCount
  14.  
  15. ReDim arrFirst(1 To intNumberOfRecords) As Integer
  16. ReDim arrSecond(1 To intNumberOfRecords) As Integer
  17.  
  18. Do While Not MyRS.EOF
  19.   T = T + 1
  20.   arrFirst(T) = MyRS![Quantity]
  21.   arrSecond(T) = arrFirst(T)
  22.   MyRS.MoveNext
  23. Loop
  24.  
  25. MyRS.Close
  26.  
  27. If intRecCounter < intNumberOfRecords Then
  28.   If intRecCounter Mod 2 <> 0 Then  'ODD Record beginning of Pair, compare DOWN
  29.     If arrFirst(intRecCounter) > arrSecond(intRecCounter + 1) Then
  30.       fReturnStatus2 = "M"
  31.     ElseIf arrFirst(intRecCounter) < arrSecond(intRecCounter + 1) Then
  32.       fReturnStatus2 = "L"
  33.     Else
  34.       fReturnStatus2 = "E"
  35.     End If
  36.   Else      'Even Record end of Pair, compare UP
  37.     If arrSecond(intRecCounter) > arrFirst(intRecCounter - 1) Then
  38.       fReturnStatus2 = "M"
  39.     ElseIf arrSecond(intRecCounter) < arrFirst(intRecCounter - 1) Then
  40.       fReturnStatus2 = "L"
  41.     Else
  42.       fReturnStatus2 = "E"
  43.     End If
  44.   End If
  45. End If
  46.  
  47. If intRecCounter = intNumberOfRecords Then intRecCounter = 0
  48. End Function
Sample Output:
Expand|Select|Wrap|Line Numbers
  1. Pairing    Individual   Quantity     Status
  2. AB        A          15           M
  3. AB        B          13           L
  4. CD        C          13           L
  5. CD        D          15           M
  6. EF        E          14           E
  7. EF        F          14           E
  8. GH        G          19           L
  9. GH        H          21           M
  10. IJ        I          47           M
  11. IJ        J          33    
  12.  
Feb 27 '07 #2
necapa82
3 New Member
Thank you very much.

It's a great help to me (and the project)!!!
Feb 27 '07 #3
Rabbit
12,516 Recognized Expert Moderator MVP
ADezii, you can call that function from a query? Whenever I try it I get an error, unknown function.
Feb 27 '07 #4
ADezii
8,834 Recognized Expert Expert
ADezii, you can call that function from a query? Whenever I try it I get an error, unknown function.
It must be declared as Public in a Standard Module in order to accessed from the Query Grid.
Feb 27 '07 #5
ADezii
8,834 Recognized Expert Expert
Thank you very much.

It's a great help to me (and the project)!!!
Glad I could help, it really had me stumped for awhile.
Feb 27 '07 #6
Rabbit
12,516 Recognized Expert Moderator MVP
It must be declared as Public in a Standard Module in order to accessed from the Query Grid.
That's what I do but it doesn't work.
Feb 27 '07 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Never mind, I'm an idiot. I didn't declare it as public, coulda sworn I did though.
Feb 27 '07 #8
NeoPa
32,568 Recognized Expert Moderator MVP
I would suggest using SQL in a format similar to :
Expand|Select|Wrap|Line Numbers
  1. UPDATE YourTable AS T INNER JOIN
  2.        (SELECT Pairing,
  3.                Min([Quantity]) AS MinQ,
  4.                Max([Quantity]) AS MaxQ
  5.         GROUP BY Pairing) AS subP
  6.     ON T.Pairing=subP.Pairing
  7. SET T.Status=IIf(subP.MinQ=subP.MaxQ,0,IIf(T.Quantity>subP.MinQ,1,-1))
Feb 28 '07 #9
ADezii
8,834 Recognized Expert Expert
I would suggest using SQL in a format similar to :
Expand|Select|Wrap|Line Numbers
  1. UPDATE YourTable AS T INNER JOIN
  2.        (SELECT Pairing,
  3.                Min([Quantity]) AS MinQ,
  4.                Max([Quantity]) AS MaxQ
  5.         GROUP BY Pairing) AS subP
  6.     ON T.Pairing=subP.Pairing
  7. SET T.Status=IIf(subP.MinQ=subP.MaxQ,0,IIf(T.Quantity>subP.MinQ,1,-1))
Interesting solution, NeoPa. Just for curiosity, has it been tested on actual data, and have the results been accurate and consistent? It's just my endless curiosity.
Feb 28 '07 #10

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

Similar topics

0
2025
by: BK | last post by:
Hi, I have a problem. I need to auto populate fields based on a value entered in combo box. Initially, I put all the required fields in the combo box, and hide it (set to 0",0",0", ...), then use code: Name=cbBox.column(3) to get the value. It works fine, but I have problem with performance. The source of the combo box is a table from another database that keeps adding up (currently we have around 1500 records, around 5-20 new records...
2
5368
by: Chand | last post by:
Hello Everyboy I am creating a small scale db with following fields in the table and form for the data entry purpose. Product ID Product Name Manufacturer Location 101 Pen ABC & Co. Boston
4
2012
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a datagrid isn't going to work). On this page, people can update a variet of records. On submit, I want to then go in and update all of the records. Normally, I'd make each form element include a runat: server and then declare it in my codebhind so I...
5
5902
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique CompanyID's. The second combobox will contain unique memberID's. Each of the tables that I have to search contain a CompanyID and a memberID field, and these fields are not unique in the respective tables. Like CompanyID, MemberID
11
7379
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and the Dropdown doesnt have any items.. The requirement is that as soon as one goes on typing the letters in the StudentName-textbox the corresponding matching names have to appear
1
7029
by: jeffro | last post by:
I have a database used for recording survey data. In the database, I have a form that displays a survey participant and a subform that is filled in by selecting a question from a looklist and then a response. The questions are held in a table and they are always the same. This is what I want to do. I want a button on the main form that can be clicked, When click, It will populate the survey detail table with the id of the record...
5
17677
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600. The species list has 7 fields the first is a four digit unique identifier (species) it is set as the primary key. I have created a relationship to the data collection table which also has a species field (4 digit id). In my form I have the species...
5
3913
FOE2272
by: FOE2272 | last post by:
I have tried every option that I can think of and most of them on this forum. The closest that I got was to bring up the field but it changed the other records based on what was chosen in one record. Details: DB with one main table and several list (reference) tables. I want to populate several list boxes on one form based on a choice from a combo box. Example: Tables:
2
3320
by: Ronald | last post by:
I hope somebody can help. I can't get into the specifics of my project, but I'll try to create a simple example: tblVehicle * VIN (text box) * Make (text box) * Model (text box) frmRepair
0
8310
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
8827
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...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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
8605
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
7333
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
5632
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
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
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

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.