Hi All, I am sure there is a way to do this but I can't figure it out. I need to refer to a variable instead of (A) a field name in recordsets and (B) a table name tabledefs. Help on either (A) or (B) would be great. Here's the code:
Code:
Private Sub UpdateFields()
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim db As DAO.Database
dim TableB as String 'or dao.table or something - I have no idea
dim FieldName as string 'or dao.field or something
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * from TableA")
TableB = "LineItemsT"
For Each fld In db.TableDefs!TableB.Fields 'TableB needs to be a variable
rs.MoveFirst
Do While Not rs.EOF
rs.Edit
FieldName = fld.name
rs!FieldName = 12345 'FieldName needs to be variable that points to a field in the rs with the same field name as fld.name from the TableB
rs.Update
rs.MoveNext
Loop
Next
rs.Close
Set rs = Nothing
End Sub