How to check the result of a SELECT query

message from =?Utf-8?B?SmFjbHlu?= on 29 May 2004
I have a SELECT query and use .EXECUTE to execute. How can I check if any record has been selected by this query? Thanks.
 
Douglas J. Steele replied to =?Utf-8?B?SmFjbHlu?= on 29 May 2004
You can't use .EXECUTE with a SELECT query: it's only intended to be used
with Action queries (INSERT INTO, UPDATE, DELETE)

With a SELETE query, you need to open a recordset, and work with it.
 
=?Utf-8?B?SmFjbHlu?= replied to Douglas J. Steele on 29 May 2004
Thanks. Do you have any sample code that I can follow?
 
Wayne Morgan replied to =?Utf-8?B?SmFjbHlu?= on 29 May 2004
This uses DAO, you may need to go to Tools|Refernces in the code editor and
check the box next to DAO, depending on your version of Access.

Dim rst As DAO.Recordset, strSQL As String
strSQL = "SELECT ....." 'fill in the rest of your query statement
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
'manipulate the recordset here to do what you want
rst.Close
Set rst = Nothing

Lookup the Recordset Object in the code editor's help to get the methods and
properties available for the object.
 
=?Utf-8?B?SmFjbHlu?= replied to Wayne Morgan on 29 May 2004
Thanks Wayne. What about ADO? Is there any corresponding to OpenRecordset? I am writing ADO and my db is SQL server.
 
Douglas J. Steele replied to =?Utf-8?B?SmFjbHlu?= on 29 May 2004
Check http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthopenx.asp
 
Albert D. Kallal replied to =?Utf-8?B?SmFjbHlu?= on 29 May 2004
'An example DAO vs ADO recordset loop, you'll see how similar they are:

'--- begin DAO ---
Dim rst As dao.Recordset

Set rst = CurrentDb.OpenRecordset("select * from contacts")
Do While rst.EOF = False
Debug.Print rst!FirstName
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
'--- end DAO ---

'--- begin ADO ---
Dim rs As New ADODB.Recordset

rs.Open ("select * from contacts"), CurrentProject.Connection
Do While rs.EOF = False
Debug.Print rs!FirstName
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
 

Archived message: How to check the result of a SELECT query (MS Access Error Message)