Getting the results of a Query in VBA

M

mdw233psu

I have a query that returns 9 rows and 5 columns. I can run the query
fine but am having trouble retrieving the results of the query. I
haven't used VBA in a few years and forget how to do this simple thing.
Here is how I run my query:

Set acQuery = CurrentDb.QueryDefs("crdAudits")

For Each prm In acQuery.Parameters
prm.Value = Eval(prm.Name)
Next prm

Set objRst = acQuery.OpenRecordset

I have tried using the objRst.fields() method, but it will only return
the first column. Is there a way to get all of the results so that i
can view all columns?

Help is greatly appreciated!
 
P

philip260

matt,

can you please detail-lify what your issue is? first i would make sure
that you have the right parentheses in place. if that solved your
problem, feel free to give me a star.

thanks
 
M

Matt

matt,

can you please detail-lify what your issue is? first i would make sure
that you have the right parentheses in place. if that solved your
problem, feel free to give me a star.

thanks






After the code above executes, I check (with a msgbox) how many rown
are returned (objRst.RecordCount). It confirms I have 9 rows returned.
I then Output objRst.fields(0) which gives me the first column in my
first row. I then output objRst.fields(1) which gives me the second
column in my first row. Then I try to output objRst.fields(3) which
says item not in collection. So I have figured the fields function
takes the column I want to see as a parameter, but I can not figure out
how to get to the next row of data. Does this make it more clear?
 
T

Tony Jollans

You need to use objRst.MoveFirst, objRst.MoveNext, etc. to move from record
(row) to record. You can then use objRst.Fields(n) or objRst!FieldName to
look at individual field (column) in the selected record.
 
M

Matt

Tony said:
You need to use objRst.MoveFirst, objRst.MoveNext, etc. to move from record
(row) to record. You can then use objRst.Fields(n) or objRst!FieldName to
look at individual field (column) in the selected record.

Tony, you are my savior. Thank you, feel kinda dumb, shoulda caught
that one, but I appreciate the help.
 

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