I have inherited an old database that I am trying to automate, I receive data from a subcontractor to which I have created a temp table. I have written a query to get me the Description and serial numbers of the sub assemblies that are fitted to the product approx 50 in total code below.
[SQL]
SELECT Product.Desc, Temp.Ser
FROM Temp INNER JOIN Product ON Temp.MRI = Product.MRI
GROUP BY Product.Desc, Temp.Ser, Product.MRI;
[Query Output]
Desc Ser
Sub Assy 1 1122
Sub Assy 2 2233
Sub Assy 3 3344
Sub Assy 4 4455
What I need to do is to update the import table which is in the following format and
Import Table
Product Sub Assy1 Sub Assy2 Sub Assy3 Sub Assy4
Sn 1234 Sn 1122 Sn 2233 Sn 3344 Sn 4455
The product serial number is already defined when selecting the import, I just need to import all the sub assys
I tried looping through both as recordsets but I kept getting an error item not found in collection
Dim fld As Fields
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Product", dbOpenDynaset)
Set rst2 = db.OpenRecordset("Import", dbOpenDynaset)
Dim Int1 As Integer
Dim Int2 As Integer
Int1 = 1
Int2 = 1
rst.MoveFirst
Do Until rst.EOF
rst2.MoveFirst
Do Until rst2.EOF
If rst![Desc] = rst2![Desc] Then
rst2.Edit
rst2![Ser] = rst![Ser]
rst2.Update
End If
rst2.MoveNext
Int1 = Int1 + 1
Loop
rst.MoveNext
Int2 = Int2 + 1
Loop
rst.Close
rst2.Close
Set rst = Nothing
Set rst2 = Nothing
MsgBox "Finised"
Any help would be really appreciated
[SQL]
SELECT Product.Desc, Temp.Ser
FROM Temp INNER JOIN Product ON Temp.MRI = Product.MRI
GROUP BY Product.Desc, Temp.Ser, Product.MRI;
[Query Output]
Desc Ser
Sub Assy 1 1122
Sub Assy 2 2233
Sub Assy 3 3344
Sub Assy 4 4455
What I need to do is to update the import table which is in the following format and
Import Table
Product Sub Assy1 Sub Assy2 Sub Assy3 Sub Assy4
Sn 1234 Sn 1122 Sn 2233 Sn 3344 Sn 4455
The product serial number is already defined when selecting the import, I just need to import all the sub assys
I tried looping through both as recordsets but I kept getting an error item not found in collection
Dim fld As Fields
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rst2 As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Product", dbOpenDynaset)
Set rst2 = db.OpenRecordset("Import", dbOpenDynaset)
Dim Int1 As Integer
Dim Int2 As Integer
Int1 = 1
Int2 = 1
rst.MoveFirst
Do Until rst.EOF
rst2.MoveFirst
Do Until rst2.EOF
If rst![Desc] = rst2![Desc] Then
rst2.Edit
rst2![Ser] = rst![Ser]
rst2.Update
End If
rst2.MoveNext
Int1 = Int1 + 1
Loop
rst.MoveNext
Int2 = Int2 + 1
Loop
rst.Close
rst2.Close
Set rst = Nothing
Set rst2 = Nothing
MsgBox "Finised"
Any help would be really appreciated