I am trying to create a function which will use variables to extract which fields are needed from an SQL statement and therefore retrieved via OpenRecordSet.
I know usually, with recordset, it's as easy as pointing to the field using '!'
For example, if I used the function:
It should somehow retrieve 'pr!truck' and message box me the value.
with pr!pName - I get "Item not found in this collection"
with pr! & pName - I get "Type-declaration character foes not match declared data type"
How can I string the variable with the RecordSet pointer?
Code:
Public Function DoSomething(pName As String)
Dim PrtSthg As String
Dim pr As DAO.Recordset
Dim tray As String
PrtSthg = "SELECT ID, Branch, " & pName & " FROM tblBranch WHERE ID=" & BranchhID & ";"
Set pr = CurrentDb.OpenRecordset(PrtSthg)
tray = pr!pName
msgBox tray
I know usually, with recordset, it's as easy as pointing to the field using '!'
For example, if I used the function:
Code:
DoSomething("truck")
with pr!pName - I get "Item not found in this collection"
with pr! & pName - I get "Type-declaration character foes not match declared data type"
How can I string the variable with the RecordSet pointer?