473,396 Members | 1,861 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,396 software developers and data experts.

Comparing array values

Hello,
I have problem in writing ms Access vba code to compare two array taken from two different recordset. One is from table: Detail Orders (PK:[Details POID],POID,Product.Code,Qty) and the other is from table [Check-In Inventory] (PK:InventoryID, POID, ProductID.Code, Qty).

I retrive the [Detail Orders] and store its values in an array and also the [Check In Inventory] in another array.

My problem is How to compare the two arrays so that I can update the inventory?

My code :
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdUpdateStock_Click()
  3.  
  4. Dim rsOrdered As New ADODB.Recordset
  5. Dim cnOrdered As New ADODB.Connection
  6. Dim rsCheckedIn As ADODB.Recordset
  7. Dim cnCheckedIn As ADODB.Connection
  8. Dim StrSql
  9. Dim arrOrdered As Variant
  10. Dim arrCheckedIn As Variant
  11.  
  12. Set cnOrdered = CurrentProject.Connection
  13.  
  14.     StrSql = "SELECT [Q Detail Order].POID, [Q Detail Order].Code, " & _
  15.              "[Q Detail Order].Qty FROM [Q Detail Order] " & _
  16.              "WHERE ([Q Detail Order].POID) = " & Me.POID.Column(0) & "  "
  17.     Set rsOrdered = cnOrdered.Execute(StrSql)
  18.  
  19.     If Not rsOrdered.EOF Then
  20.         rsOrdered.MoveFirst
  21.         Do While Not rsOrdered.EOF
  22.             arrOrdered = rsOrdered.GetRows()
  23.         If Not rsOrdered.EOF Then
  24.             rsOrdered.MoveNext
  25.         End If
  26.         Loop
  27.     End If
  28.  
  29. ' retriver another recordset from [Check-In Inventory]
  30. .
  31.    arrCheckedIn = rsCheckedIn.GetRows()
  32.  
  33. 'Comparing the two array's values
  34.   < what code should i write?>
  35.  
  36. ' clean up
  37.     rsOrdered.Close
  38.     cnOrdered.Close
  39.     Set rsOrdered = Nothing
  40.     Set cnOrdered = Nothing
  41.     .
  42.     .
  43.     .
  44. End Sub
  45.  
  46.  
Could you help me Please?

TQ in advance
Nov 7 '06 #1
3 8638
MMcCarthy
14,534 Expert Mod 8TB
Hello,
I have problem in writing ms Access vba code to compare two array taken from two different recordset. One is from table: Detail Orders (PK:[Details POID],POID,Product.Code,Qty) and the other is from table [Check-In Inventory] (PK:InventoryID, POID, ProductID.Code, Qty).

I retrive the [Detail Orders] and store its values in an array and also the [Check In Inventory] in another array.

My problem is How to compare the two arrays so that I can update the inventory?
Firstly, I would use DAO to do this instead of ADO.


Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdUpdateStock_Click()
  3. Dim db As DAO.Database 
  4. Dim rsOrdered As DAO.Recordset
  5. Dim rsCheckedIn As DAO.Recordset
  6. Dim StrSql As String
  7. Dim arrOrdered As Variant
  8. Dim arrCheckedIn As Variant
  9.  
  10. Set db = CurrentDb
  11.  
  12. Set rsOrdered = db.OpenRecordset("Detail Orders")
  13. Set rsCheckedIn = db.OpenRecordset("Check-In Inventory")
  14.  
  15. If Not rsOrdered.EOF And Not rs.Ordered.BOF Then
  16.   rsOrdered.MoveFirst
  17.   Do Until rsOrdered.EOF
  18.     rsCheckedIn.FindFirst rsCheckedIn!POID=rsOrdered!POID
  19.     If Not rsCheckedIn.NoMatch Then
  20.       rsCheckedIn.Edit
  21.       '<I don't know exactly what you want to do here>
  22.       rsCheckedIn.Update
  23.       Do Until rsCheckedIn.EOF
  24.         rsCheckedIn.FindNext rsCheckedIn!POID=rsOrdered!POID
  25.         If Not rsCheckedIn.NoMatch Then
  26.           rsCheckedIn.Edit
  27.           '<I don't know exactly what you want to do here> 
  28.           rsCheckedIn.Update
  29.         End If
  30.       Loop
  31.     End If
  32.     rs.MoveNext
  33.   Loop
  34. End If
  35.  
  36.  
  37. ' clean up
  38. rsOrdered.Close
  39. rsCheckedIn.Close
  40. Set rsOrdered = Nothing
  41. Set rsCheckedIn = Nothing
  42. Set db = Nothing
  43.  
  44. End Sub
  45.  
  46.  
Nov 7 '06 #2
Firstly, I would use DAO to do this instead of ADO.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdUpdateStock_Click()
  2. Dim db As DAO.Database 
  3. Dim rsOrdered As DAO.Recordset
  4. Dim rsCheckedIn As DAO.Recordset
  5. Dim StrSql As String
  6. Dim arrOrdered As Variant
  7. Dim arrCheckedIn As Variant
  8.  
  9. Set db = CurrentDb
  10.  
  11. Set rsOrdered = db.OpenRecordset("Detail Orders")
  12. Set rsCheckedIn = db.OpenRecordset("Check-In Inventory")
  13.  
  14. If Not rsOrdered.EOF And Not rs.Ordered.BOF Then
  15.   rsOrdered.MoveFirst
  16.   Do Until rsOrdered.EOF
  17.     rsCheckedIn.FindFirst rsCheckedIn!POID=rsOrdered!POID
  18.     If Not rsCheckedIn.NoMatch Then
  19.       rsCheckedIn.Edit
  20.       '<I don't know exactly what you want to do here>
  21.       rsCheckedIn.Update
  22.       Do Until rsCheckedIn.EOF
  23.         rsCheckedIn.FindNext rsCheckedIn!POID=rsOrdered!POID
  24.         If Not rsCheckedIn.NoMatch Then
  25.           rsCheckedIn.Edit
  26.           '<I don't know exactly what you want to do here> 
  27.           rsCheckedIn.Update
  28.         End If
  29.       Loop
  30.     End If
  31.     rs.MoveNext
  32.   Loop
  33. End If
  34.  
  35.  
  36. ' clean up
  37. rsOrdered.Close
  38. rsCheckedIn.Close
  39. Set rsOrdered = Nothing
  40. Set rsCheckedIn = Nothing
  41. Set db = Nothing
  42.  
  43. End Sub
  44.  
  45.  
Why would you use DAO instead of ADO? Isn't ADO is much more powerful than ADO according to Microsoft?
I want to compare those arrays so that if the goods arrived is less than what was ordered, it will then store the Qty Leg into QtlLeg Table together with the purchase Order number (POID) and other entities needed,

Else if it's equal, the inventory table will be updated.

Thx 4 ur Help.
Nov 9 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Why would you use DAO instead of ADO? Isn't ADO is much more powerful than ADO according to Microsoft?
Check out the following threads as they express it quite comprehensively. It is an ongoing hot argument but the conclusions of the MVP's who are essentially the Microsoft Approved experts is that DAO is the appropriate connection to use with the Jet Engine. In other words when using mdbs or mdes.

http://www.thescripts.com/forum/thread190264.html

http://www.thescripts.com/forum/thre...0516-2-10.html

http://www.thescripts.com/forum/thre...8231-4-10.html



I want to compare those arrays so that if the goods arrived is less than what was ordered, it will then store the Qty Leg into QtlLeg Table together with the purchase Order number (POID) and other entities needed,

Else if it's equal, the inventory table will be updated.
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdUpdateStock_Click()
  3. Dim db As DAO.Database 
  4. Dim rsOrdered As DAO.Recordset
  5. Dim rsCheckedIn As DAO.Recordset
  6. Dim StrSql As String
  7. Dim arrOrdered As Variant
  8. Dim arrCheckedIn As Variant
  9.  
  10. Set db = CurrentDb
  11.  
  12. Set rsOrdered = db.OpenRecordset("Detail Orders")
  13. Set rsCheckedIn = db.OpenRecordset("Check-In Inventory")
  14.  
  15. If Not rsOrdered.EOF And Not rs.Ordered.BOF Then
  16.   rsOrdered.MoveFirst
  17.   Do Until rsOrdered.EOF
  18.     rsCheckedIn.FindFirst rsCheckedIn!POID=rsOrdered!POID
  19.         If Not rsCheckedIn.NoMatch Then
  20.           If rsCheckedIn!Qty < rsOrdered!Qty Then
  21.         DoComd.RunSQL "INSERT INTO QtyLeg (POID, Qty) " & _
  22.             "VALUES (" & rsCheckedIn!POID & "," & rsOrdered!Qty-rsCheckedIn!Qty & ");"
  23.       End If
  24.       Do Until rsCheckedIn.EOF
  25.         rsCheckedIn.FindNext rsCheckedIn!POID=rsOrdered!POID
  26.         If Not rsCheckedIn.NoMatch Then
  27.           If rsCheckedIn!Qty < rsOrdered!Qty Then
  28.             DoComd.RunSQL "INSERT INTO QtyLeg (POID, Qty) " & _
  29.                 "VALUES (" & rsCheckedIn!POID & "," & rsOrdered!Qty-rsCheckedIn!Qty & ");"
  30.           End If           
  31.         End If
  32.           Loop
  33.     End If
  34.     rs.MoveNext
  35.   Loop
  36. End If
  37.  
  38. ' clean up
  39. rsOrdered.Close
  40. rsCheckedIn.Close
  41. Set rsOrdered = Nothing
  42. Set rsCheckedIn = Nothing
  43. Set db = Nothing
  44.  
  45. End Sub
  46.  
  47.  
Nov 10 '06 #4

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

Similar topics

12
by: Elijah Bailey | last post by:
I have two char arrays of size k. I want to know which one is bigger (exactly like for instance I compare two ints/longs/etc.). What is the fastest way to do this? k <= 10 usually for my...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
2
by: darrel | last post by:
I have two comma delimted strings that I need to compare individual values between the two. I assume the solution is likely to put them into an array? If so, do I need to loop through one,...
1
by: psmahesh | last post by:
Hi folks, I am comparing two arrays and removing matches from the second array from the first array. Can someone take a look at this code below and mention if this is okay and perhaps if there...
20
by: Bill Pursell | last post by:
This question involves code relying on mmap, and thus is not maximally portable. Undoubtedly, many will complain that my question is not topical... I have two pointers, the first of which is...
25
by: galapogos | last post by:
Hi, I'm trying to compare an array of unsigned chars(basically just data without any context) with a constant, and I'm not sure how to do that. Say my array is array and I want to compare it with...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
5
by: SneakyElf | last post by:
I need to write a function where the third parameter points to an address whose dereferenced value equals one of the array element's value, then the the function returns the index of the first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.