Using variable to reference table field for updating

elliotgr

Registered User.
Local time
Today, 15:12
Joined
Dec 30, 2010
Messages
67
I have a variable that must determine what field must be populated in a table. Is this possible?

Code:
Sub Get_Variable_Field_Name()
 
dim db as database
dim rst as recordset
 
set db = Currentdb
set rst = OpenRecordset("MyRecordSet")
 
VarFieldName = "Valid table field name goes here"
 
rst.addnew
rst!("How do I reference the varable as a field name") = "MyFieldValue"
rst.update
 
rst.close
db.close
set rst = nothing
set db = nothing
end sub
 
Thanks, but sorry, no joy when trying to update the field.

This works

Code:
rst!MESSAGE = "Hello"

but this does not

Code:
dim strField as string
strField = "MESSAGE"
rst!Fields(strField) = "Hello"

I get error 3265, item not found in this collection.
 
Please re-read my post and follow the exact syntax.
 
My mistake, typing error, but had a data conversion error throwing me off track. (Field variable was a date, so I had to force it to as string). Once that was fixed, all works fine
 

Users who are viewing this thread

Back
Top Bottom