M
Mike Thomas
In Access 2003, DAO, I have a situation where I need to get a field's value
where I know the field name only as the contents of a string variable. The
very simplified example below demonstrates this more easily than I can
explain it.
Some code ...
strSQL = "Select * From mytable Where ID = 3"
Set r = db.openrecordset(strSQL, dbopenforwardonly)
strFieldValue = r!SomeField '' would work, but not possible in this snippet
strFieldName = "SomeField"
strFieldValue = r!strFieldName '' obviously gives 'no such field name'
error
Is there a way to code the above so that I can use the variable strFieldName
to accomplish the same thing as r!SomeField?
In my old days as a VFP programmer we called this macro substitution, where
strFieldName = "r!" + strFieldName, then strFieldValue = &strFieldName would
have worked.
Many thanks
Mike Thomas
where I know the field name only as the contents of a string variable. The
very simplified example below demonstrates this more easily than I can
explain it.
Some code ...
strSQL = "Select * From mytable Where ID = 3"
Set r = db.openrecordset(strSQL, dbopenforwardonly)
strFieldValue = r!SomeField '' would work, but not possible in this snippet
strFieldName = "SomeField"
strFieldValue = r!strFieldName '' obviously gives 'no such field name'
error
Is there a way to code the above so that I can use the variable strFieldName
to accomplish the same thing as r!SomeField?
In my old days as a VFP programmer we called this macro substitution, where
strFieldName = "r!" + strFieldName, then strFieldValue = &strFieldName would
have worked.
Many thanks
Mike Thomas