I'm using a DAO.recordset (called rs2) based on an SQL query (in MS Access). Calling the individual attributes in the recordset works just fine, as follows:
strName = rs2!Name
strDescr = rs2!Descr
I am trying to come up with a more generic way reference the attributes via a variable, without success, using the Eval() function.
Is something like this even possible?
strAttr = "Name"
strResult = Eval("rs2!" & strAttr)
Any suggestions to accomplish?
Eval() is evaluated by the Access expression service. And that service doesn't have any awareness of VBA variables, including object variables such as your rs2 recordset.
But I don't think you need something like Eval() to get what you want. Use strAttr to reference that named field in the recordset's .Fields collection.
strAttr = "Name"
strResult = rs2.Fields(strAttr).Value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With