I am a beginner VBA user. I need to compare two tables in Access (97) and display results in a column in each table.
The 'reschedule' table has the following fields: Item, NeededQty, NeededDate, count. The 'po' table has the following fields: Item, PO, Qty, DueDate, count1. I need to be able to count between the two tables using the item as the link. I'm looking for an end result that looks like this:
Table A Table B
Reschedules PO's
Item Count Item1 Count1
1234 1 1234 2
1234 3 1234 4
1234 5 1244 7
1244 6 1244 9
1244 8 1255 11
1255 10 1266 13
1266 12 1277 16
1266 14
1277 15
'where it finds matching items it puts a count - if there's more PO lines than reschedule lines it leave the count blank. There can be more PO's than reschedule but never more reschedules than PO's.
I have been trying to use the following code :
Function Test11a()
Dim count As Integer
Dim count2 As Integer
Dim db As Database
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim strMsg As String
Dim varReturn As Integer
Dim Item1 As String
Dim Item2 As String
count = 0
Set db = DBEngine(0)(0)
Set rs1 = db.OpenRecordset("Net Reqs To Reschedule", dbOpenDynaset)
Set rs2 = db.OpenRecordset("Open PO's", dbOpenDynaset)
rs1.MoveFirst
rs2.MoveFirst
strMsg = "Counting Records " & "..."
varReturn = SysCmd(acSysCmdInitMeter, strMsg, rs1.RecordCount)
Do While Not rs1.EOF 'Outer Loop
Item1 = rs1("Item"
count = count + 1
varReturn = SysCmd(acSysCmdUpdateMeter, count)
rs1.Edit
rs1("Count" = count
rs1.Update
Do Until Item2 > Item1 'Inner Loop
Item2 = rs2("Item"
strMsg = "Counting PO " & "..."
varReturn = SysCmd(acSysCmdInitMeter, strMsg, rs1.RecordCount)
If Item1 = Item2 Then
count = count + 1
varReturn = SysCmd(acSysCmdUpdateMeter, count2)
rs2.Edit
rs2("Count2" = count
rs2.Update
rs2.MoveNext
End If
Loop
rs1.MoveNext
Loop
varReturn = SysCmd(acSysCmdRemoveMeter)
Exit Function
End Function
The 'reschedule' table has the following fields: Item, NeededQty, NeededDate, count. The 'po' table has the following fields: Item, PO, Qty, DueDate, count1. I need to be able to count between the two tables using the item as the link. I'm looking for an end result that looks like this:
Table A Table B
Reschedules PO's
Item Count Item1 Count1
1234 1 1234 2
1234 3 1234 4
1234 5 1244 7
1244 6 1244 9
1244 8 1255 11
1255 10 1266 13
1266 12 1277 16
1266 14
1277 15
'where it finds matching items it puts a count - if there's more PO lines than reschedule lines it leave the count blank. There can be more PO's than reschedule but never more reschedules than PO's.
I have been trying to use the following code :
Function Test11a()
Dim count As Integer
Dim count2 As Integer
Dim db As Database
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim strMsg As String
Dim varReturn As Integer
Dim Item1 As String
Dim Item2 As String
count = 0
Set db = DBEngine(0)(0)
Set rs1 = db.OpenRecordset("Net Reqs To Reschedule", dbOpenDynaset)
Set rs2 = db.OpenRecordset("Open PO's", dbOpenDynaset)
rs1.MoveFirst
rs2.MoveFirst
strMsg = "Counting Records " & "..."
varReturn = SysCmd(acSysCmdInitMeter, strMsg, rs1.RecordCount)
Do While Not rs1.EOF 'Outer Loop
Item1 = rs1("Item"
count = count + 1
varReturn = SysCmd(acSysCmdUpdateMeter, count)
rs1.Edit
rs1("Count" = count
rs1.Update
Do Until Item2 > Item1 'Inner Loop
Item2 = rs2("Item"
strMsg = "Counting PO " & "..."
varReturn = SysCmd(acSysCmdInitMeter, strMsg, rs1.RecordCount)
If Item1 = Item2 Then
count = count + 1
varReturn = SysCmd(acSysCmdUpdateMeter, count2)
rs2.Edit
rs2("Count2" = count
rs2.Update
rs2.MoveNext
End If
Loop
rs1.MoveNext
Loop
varReturn = SysCmd(acSysCmdRemoveMeter)
Exit Function
End Function