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

  • Thread starter Thread starter LisaB
  • Start date Start date
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
 
rst.Fields(FieldName)

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

rst!FieldName

HTH,
 
Back
Top