Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Eval() with DAO.Recordset - Possible?

Tags:

vba

ms-access

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?

like image 616
Mark Pelletier Avatar asked Feb 11 '26 19:02

Mark Pelletier


1 Answers

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
like image 117
HansUp Avatar answered Feb 13 '26 15:02

HansUp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!