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 : -
-
Private Sub cmdUpdateStock_Click()
-
-
Dim rsOrdered As New ADODB.Recordset
-
Dim cnOrdered As New ADODB.Connection
-
Dim rsCheckedIn As ADODB.Recordset
-
Dim cnCheckedIn As ADODB.Connection
-
Dim StrSql
-
Dim arrOrdered As Variant
-
Dim arrCheckedIn As Variant
-
-
Set cnOrdered = CurrentProject.Connection
-
-
StrSql = "SELECT [Q Detail Order].POID, [Q Detail Order].Code, " & _
-
"[Q Detail Order].Qty FROM [Q Detail Order] " & _
-
"WHERE ([Q Detail Order].POID) = " & Me.POID.Column(0) & " "
-
Set rsOrdered = cnOrdered.Execute(StrSql)
-
-
If Not rsOrdered.EOF Then
-
rsOrdered.MoveFirst
-
Do While Not rsOrdered.EOF
-
arrOrdered = rsOrdered.GetRows()
-
If Not rsOrdered.EOF Then
-
rsOrdered.MoveNext
-
End If
-
Loop
-
End If
-
-
' retriver another recordset from [Check-In Inventory]
-
.
-
arrCheckedIn = rsCheckedIn.GetRows()
-
-
'Comparing the two array's values
-
< what code should i write?>
-
-
' clean up
-
rsOrdered.Close
-
cnOrdered.Close
-
Set rsOrdered = Nothing
-
Set cnOrdered = Nothing
-
.
-
.
-
.
-
End Sub
-
-
Could you help me Please?
TQ in advance
3 8638
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. -
-
Private Sub cmdUpdateStock_Click()
-
Dim db As DAO.Database
-
Dim rsOrdered As DAO.Recordset
-
Dim rsCheckedIn As DAO.Recordset
-
Dim StrSql As String
-
Dim arrOrdered As Variant
-
Dim arrCheckedIn As Variant
-
-
Set db = CurrentDb
-
-
Set rsOrdered = db.OpenRecordset("Detail Orders")
-
Set rsCheckedIn = db.OpenRecordset("Check-In Inventory")
-
-
If Not rsOrdered.EOF And Not rs.Ordered.BOF Then
-
rsOrdered.MoveFirst
-
Do Until rsOrdered.EOF
-
rsCheckedIn.FindFirst rsCheckedIn!POID=rsOrdered!POID
-
If Not rsCheckedIn.NoMatch Then
-
rsCheckedIn.Edit
-
'<I don't know exactly what you want to do here>
-
rsCheckedIn.Update
-
Do Until rsCheckedIn.EOF
-
rsCheckedIn.FindNext rsCheckedIn!POID=rsOrdered!POID
-
If Not rsCheckedIn.NoMatch Then
-
rsCheckedIn.Edit
-
'<I don't know exactly what you want to do here>
-
rsCheckedIn.Update
-
End If
-
Loop
-
End If
-
rs.MoveNext
-
Loop
-
End If
-
-
-
' clean up
-
rsOrdered.Close
-
rsCheckedIn.Close
-
Set rsOrdered = Nothing
-
Set rsCheckedIn = Nothing
-
Set db = Nothing
-
-
End Sub
-
-
Firstly, I would use DAO to do this instead of ADO. -
Private Sub cmdUpdateStock_Click()
-
Dim db As DAO.Database
-
Dim rsOrdered As DAO.Recordset
-
Dim rsCheckedIn As DAO.Recordset
-
Dim StrSql As String
-
Dim arrOrdered As Variant
-
Dim arrCheckedIn As Variant
-
-
Set db = CurrentDb
-
-
Set rsOrdered = db.OpenRecordset("Detail Orders")
-
Set rsCheckedIn = db.OpenRecordset("Check-In Inventory")
-
-
If Not rsOrdered.EOF And Not rs.Ordered.BOF Then
-
rsOrdered.MoveFirst
-
Do Until rsOrdered.EOF
-
rsCheckedIn.FindFirst rsCheckedIn!POID=rsOrdered!POID
-
If Not rsCheckedIn.NoMatch Then
-
rsCheckedIn.Edit
-
'<I don't know exactly what you want to do here>
-
rsCheckedIn.Update
-
Do Until rsCheckedIn.EOF
-
rsCheckedIn.FindNext rsCheckedIn!POID=rsOrdered!POID
-
If Not rsCheckedIn.NoMatch Then
-
rsCheckedIn.Edit
-
'<I don't know exactly what you want to do here>
-
rsCheckedIn.Update
-
End If
-
Loop
-
End If
-
rs.MoveNext
-
Loop
-
End If
-
-
-
' clean up
-
rsOrdered.Close
-
rsCheckedIn.Close
-
Set rsOrdered = Nothing
-
Set rsCheckedIn = Nothing
-
Set db = Nothing
-
-
End Sub
-
-
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.
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: -
-
Private Sub cmdUpdateStock_Click()
-
Dim db As DAO.Database
-
Dim rsOrdered As DAO.Recordset
-
Dim rsCheckedIn As DAO.Recordset
-
Dim StrSql As String
-
Dim arrOrdered As Variant
-
Dim arrCheckedIn As Variant
-
-
Set db = CurrentDb
-
-
Set rsOrdered = db.OpenRecordset("Detail Orders")
-
Set rsCheckedIn = db.OpenRecordset("Check-In Inventory")
-
-
If Not rsOrdered.EOF And Not rs.Ordered.BOF Then
-
rsOrdered.MoveFirst
-
Do Until rsOrdered.EOF
-
rsCheckedIn.FindFirst rsCheckedIn!POID=rsOrdered!POID
-
If Not rsCheckedIn.NoMatch Then
-
If rsCheckedIn!Qty < rsOrdered!Qty Then
-
DoComd.RunSQL "INSERT INTO QtyLeg (POID, Qty) " & _
-
"VALUES (" & rsCheckedIn!POID & "," & rsOrdered!Qty-rsCheckedIn!Qty & ");"
-
End If
-
Do Until rsCheckedIn.EOF
-
rsCheckedIn.FindNext rsCheckedIn!POID=rsOrdered!POID
-
If Not rsCheckedIn.NoMatch Then
-
If rsCheckedIn!Qty < rsOrdered!Qty Then
-
DoComd.RunSQL "INSERT INTO QtyLeg (POID, Qty) " & _
-
"VALUES (" & rsCheckedIn!POID & "," & rsOrdered!Qty-rsCheckedIn!Qty & ");"
-
End If
-
End If
-
Loop
-
End If
-
rs.MoveNext
-
Loop
-
End If
-
-
' clean up
-
rsOrdered.Close
-
rsCheckedIn.Close
-
Set rsOrdered = Nothing
-
Set rsCheckedIn = Nothing
-
Set db = Nothing
-
-
End Sub
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 =...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |