Replacing a field name in the 'With' statement with a variable name

L

LisaB

If I want to run this function where I bring in the field name, how do I
substitute the fieldname with the variable name. For example: in the
function below I want to replace !Title with the variable FieldName. How do
I reference it
--------------------------
Function ChangeFieldValue (FieldName as string, Value as string)

Set dbs = OpenDatabase("Northwind.mdb")
Set rst = dbs.OpenRecordset("TableName", dbOpenDynaset)

With rst
.Edit
!Title = Value
.Update
End With

I want it this but I get an error

With rst
.Edit
!FieldName = Value
.Update
End With
 
G

George Nicholson

rst.Fields(FieldName)

would allow you to substitute your variable and should be the same as

rst!FieldName

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top