I am trying to copy data from one table to another, but the tables have different variable names. So I have a table named LayoutMatrix that has the names from one table that correspond to the names of the other table. Ie. ID, OldName, GlobalFieldName. I cant append it using SQL, but sometimes some records dont paste due to conversion, so im trying to use Recordsets to trap the errors. I have gotten this far. Is there a way to find the record where OldName="value" and then retrieve what the corresponding GlobalFieldName is?
Code:
For Each tdf In db.TableDefs
'If its a CAHSEE results table then assign the layout from the description
If Left(tdf.Name, 6) = "CAHSEE" Or Left(tdf.Name, 4) = "HSEE" Then
strlayout = Mid(tdf.Properties("Description"), 7, 4)
Set rsnew = db.OpenRecordset("PUSDRESULTSTRIAL") 'To table
Set rsold = db.OpenRecordset(tdf.Name) 'From table
rsold.MoveFirst ' go to the first record in the old table
j = 1 'Begin Count of records
While Not rsold.EOF
rsnew.AddNew
For Each fld In rsold.Fields
rst.FindFirst ("[" & strlayout & "]= '" & fld.Name & "'")
strname = rst.Fields("GlobalFieldName")
[b]rsnew.Fields(strname) = fld[/b]
Next fld
rsnew.Update
j = j + 1
rsold.MoveNext
Wend
MsgBox j & " record(s) have been added", vbExclamation + vbOKOnly
End If
Next tdf