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,
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. - Calculated Field ==> Status: fReturnStatus2([Quantity])
- Public Function fReturnStatus2(MyQuantity As Integer)
-
Dim MyDB As Database, MyRS As Recordset
-
Static intRecCounter As Integer
-
Dim intNumberOfRecords As Integer
-
Dim T As Integer
-
-
intRecCounter = intRecCounter + 1 'Current Record Number
-
Set MyDB = CurrentDb()
-
Set MyRS = MyDB.OpenRecordset("tblPairings", dbOpenDynaset)
-
-
MyRS.MoveLast: MyRS.MoveFirst
-
-
intNumberOfRecords = MyRS.RecordCount
-
-
ReDim arrFirst(1 To intNumberOfRecords) As Integer
-
ReDim arrSecond(1 To intNumberOfRecords) As Integer
-
-
Do While Not MyRS.EOF
-
T = T + 1
-
arrFirst(T) = MyRS![Quantity]
-
arrSecond(T) = arrFirst(T)
-
MyRS.MoveNext
-
Loop
-
-
MyRS.Close
-
-
If intRecCounter < intNumberOfRecords Then
-
If intRecCounter Mod 2 <> 0 Then 'ODD Record beginning of Pair, compare DOWN
-
If arrFirst(intRecCounter) > arrSecond(intRecCounter + 1) Then
-
fReturnStatus2 = "M"
-
ElseIf arrFirst(intRecCounter) < arrSecond(intRecCounter + 1) Then
-
fReturnStatus2 = "L"
-
Else
-
fReturnStatus2 = "E"
-
End If
-
Else 'Even Record end of Pair, compare UP
-
If arrSecond(intRecCounter) > arrFirst(intRecCounter - 1) Then
-
fReturnStatus2 = "M"
-
ElseIf arrSecond(intRecCounter) < arrFirst(intRecCounter - 1) Then
-
fReturnStatus2 = "L"
-
Else
-
fReturnStatus2 = "E"
-
End If
-
End If
-
End If
-
-
If intRecCounter = intNumberOfRecords Then intRecCounter = 0
-
End Function
Sample Output: -
Pairing Individual Quantity Status
-
AB A 15 M
-
AB B 13 L
-
CD C 13 L
-
CD D 15 M
-
EF E 14 E
-
EF F 14 E
-
GH G 19 L
-
GH H 21 M
-
IJ I 47 M
-
IJ J 33
-
Thank you very much.
It's a great help to me (and the project)!!!
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.
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.
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.
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.
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.
NeoPa 32,568
Recognized Expert Moderator MVP
I would suggest using SQL in a format similar to : - UPDATE YourTable AS T INNER JOIN
-
(SELECT Pairing,
-
Min([Quantity]) AS MinQ,
-
Max([Quantity]) AS MaxQ
-
GROUP BY Pairing) AS subP
-
ON T.Pairing=subP.Pairing
-
SET T.Status=IIf(subP.MinQ=subP.MaxQ,0,IIf(T.Quantity>subP.MinQ,1,-1))
ADezii 8,834
Recognized Expert Expert
I would suggest using SQL in a format similar to : - UPDATE YourTable AS T INNER JOIN
-
(SELECT Pairing,
-
Min([Quantity]) AS MinQ,
-
Max([Quantity]) AS MaxQ
-
GROUP BY Pairing) AS subP
-
ON T.Pairing=subP.Pairing
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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...
|
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
|
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
| |
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...
|
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...
|
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:
|
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
|
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,...
|
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: 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...
|
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,...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |