Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically accessing a table value ...

Status
Not open for further replies.

act

Programmer
Jun 15, 2000
5
GB
I am trying to write a general funation to output the data in a table or query in a predefined format. I can get a list of the fields in recordset, but I don't know how to code up the dtaement to pick up the data. for example:

strfield = "field1"

print #1, [mytable]! strfield <- this shoudl evaluate to a piece of data.

I've tried using the Eval function, but the resultant expression doen't get compiled correctly.

Regards,

Adrian
 

If I understand the question, the following :
&quot;print #1, [mytable]! strfield <- this shoudl evaluate to a piece of data.&quot;, won't work.

You did not include the code that creates the recordset from the table or query, but since I am sure that you are aware that you will be needing a recordset (to extract the field values from) I offer the following.


Sub DoGetSomeFields()

'first create a recordset using something like...
Dim mytable as Recordset
Dim db as Database
set db = DBEngine(0)(0) ' the current workspace and database
Set mytable = db.OpenRecordset(&quot;qryQuery1&quot;)

'... then you can use
'print #1, mytable(&quot;fieldName&quot;) , or
'print #1, mytable.Fields(&quot;fieldName&quot;) , or
'print #1, mytable.Fields(1) , this one uses the field position.

End Sub



This should get you started.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top