Forum Discussion
Jeo0o7
Jul 18, 2021Copper Contributor
How do I refer to a table field name in vba code during update process?
Here is my code: Public Function fnGeneral Dim rs As DAO.Recordset Dim ss As String Dim aLetter(1 To 14) As String Dim lGrid As Long Dim iLetter As Long Dim sField As...
Jeo0o7
Jul 18, 2021Copper Contributor
Thanks George. You have it correct about my goal. If you run my code you get a "Not in collection" error at the place you discussed. The variable has the correct field name , A1, as its value, but produces the error when you use that sField variable fot updating. It seems to me the local variable is being taken literally instead of being able to represent the value of the FieldName in the updating process.
George_Hepworth
Jul 19, 2021Silver Contributor
I see. Thanks for the clarification.
If you want to address variable fields, you have to use the Recordset.Fields(x) collection, where x is either the index for the field in question, or the name of that field.
- Jeo0o7Jul 19, 2021Copper ContributorThanks so much for the replies, George. I know you are correct! I understand, and will work on it that way!
- Jeo0o7Jul 19, 2021Copper ContributorAll I needed was the correct way of referencing:
Also, wild card in sql statement was ok to use.
Thanks for everything, George!
sField = "A1"
With rs
.Edit
.Fields(sField) = "B"
.Update
End With- George_HepworthJul 19, 2021Silver ContributorCongratulations on solving the problem.
Continued success with the project.