How do I use query results in code???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys.
I've written a query that selects one record from a table and sets the query
itself in a variable.

Now, I want to use the query's fields values individually to populate some
label captions on a form.

What is the best method for extracting query field values from the query
itself?
 
hi Steve,

Steve said:
Now, I want to use the query's fields values individually to populate some
label captions on a form.
What is the best method for extracting query field values from the query
itself?
VBA:

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("yourQuery")

lblXXX.Caption = rs![FieldX]

rs.Close
Set rs = Nothing



mfG
--> stefan <--
 
Hi Steve,
I would do in this way (assuming you've all the value in the same record of
the query)
dim db as database
dim rec as recordset
Set db =currentdb
set rec=db.openrecordset("select * from nameof your query where if you want
to extract a particular record from your query put the conditions
here",dbopendynaset)
nameofyourfirstlabel.caption=rec![nameofthefieldofyourqueryfromwhichfetchthevalue]
etc.etc. for all the value ypu wanna pick from the query.

rec.close
db.close

HTH Paolo
 
Thanks guys! I think I'll try Stefan's way first, but it appears that both
of you are right on the ball.

THANKS!!!!
 
Back
Top