MS Access Continuous Form - Retrieve row Key in VBA

What is the best way to retrieve a rows key value if you include the key field in the query but don't bind it to a text box?
LVL 6
AkAlanAsked:
Who is Participating?
 
peter57rCommented:
In code you can use   me.keyfieldname   whether or not the field is on the form.  It must be in the form's recordsource of course.
0
 
AkAlanAuthor Commented:
Peter, Thanks, I had thought you could do that but when I tried to use that method to set a parameter directly in an ADODB Command, it didn't work, I had to first declare a variable, then set the variable to the keyvalue, then I used the variable in the Command.

Does Not work

Dim cmd as New ADODB.Command
With cmd
 .Parameters(@MyKeyValue") = Me.MyKeyValue


Does Work:

Dim myKeyValue as integer
myKeyValue = Me.MyKeyValue

Dim cmd as New ADODB.Command
With cmd
 .Parameters(@MyKeyValue") = myKeyValue
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.