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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.RunSQL with SELECT

Status
Not open for further replies.

almoes

Programmer
Jan 8, 2003
291
US
Hi all!

Is it possible at all to Use DoCmd.RunSQL to make a SELECT on a table and retrieve the info? If yes, how? the RunSQL is a Sub so I don't know how to retrieve the data result of the query :-( thanxs!

cheers,
alej
 
No - the runsql method of the docmd object is only good for runnig action queries. You'd need a recordset.

Simple sample (requires a reference to Microsoft DAO 3.# Object Library - In VBE - Tools | References)

[tt]dim rs as dao.recordset
set rs=currentdb.openrecordset("select field1, field2 from sometable")
do while not rs.eof
debug.print rs.fields("field1"), rs.fields("field2")
rs.movenext
loop
rs.close
set rs=nothing[/tt]

- hit ctrl+g to study the results, for more samples, do a search here...

Roy-Vidar
 
Cool! does this influence in performance? thanxs!

alej
 
Everything you do, influence performance.

Using a recordset to fetch information is among the faster methods. But everything will depend on setup, number of records, indexes, linked vs native tables, selecting the minimum number of columns vs "select *"...

Here's a couple of performance links Microsoft Access Performance FAQ, Making Access Faster - 168 Tips to Speed Up Your Apps!.

Roy-Vidar
 
OK cool!

now if I have the following SQL: Select MAX(ID) from... the recordset has no field name! How can I get this value???

thanxs,
alej
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top