Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Getting the results of a Query in VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mdw233psu@yahoo.com - 18 Sep 2006 21:23 GMT
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!
philip260@gmail.com - 18 Sep 2006 21:37 GMT
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?
Tony Jollans - 18 Sep 2006 22:02 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
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.