EVAL not working with recordset variable

M

Murray Hopkins

Hi,

I am trying to use Eval with an adodb recordset variable in MS Access 2003.

I am getting the error "can't find the name 'rs' you entered in the
expression".

This way works:
x = rs!CardRecordID

This way doesnt:
y = Eval("rs!" & "CardRecordID")

I am using eval because in the real function the fieldname is passed in as a
parameter:

y = Eval("rs!" & fldname)

I know I can loop through the recordset.fields collection until I find the
one I want but I am curious why the eval wont work.

The full code is:

Private Sub Command1_Click()
Dim myDSN As String
Dim rs As ADODB.Recordset
Dim x As Variant
Dim y As Variant

myDSN = "NCT"
Set myobCon = New ADODB.Connection
myobCon.CursorLocation = adUseClient
myobCon.Open myDSN
x = Null

Set rs = myobCon.Execute("SELECT CardRecordID From Cards")

rs.MoveLast

x = rs!CardRecordID ' This works
y = Eval("rs!" & "CardRecordID") ' This doesnt

rs.Close
myobCon.Close
Set myobCon = Nothing
End Sub
 

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