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!
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
> 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
[quoted text clipped - 14 lines]
>
> Help is greatly appreciated!
Matt - 18 Sep 2006 21:47 GMT
philip...@gmail.com wrote:
> matt,
>
[quoted text clipped - 22 lines]
> >
> > Help is greatly appreciated!
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?
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.
--
Enjoy,
Tony
> 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
[quoted text clipped - 14 lines]
>
> Help is greatly appreciated!
Matt - 19 Sep 2006 13:43 GMT
> 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
[quoted text clipped - 22 lines]
> >
> > Help is greatly appreciated!
Tony, you are my savior. Thank you, feel kinda dumb, shoulda caught
that one, but I appreciate the help.