Thread: ADO question
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_5_] GS[_5_] is offline
external usenet poster
 
Posts: 226
Default ADO question

Robert Crandal pretended :
My VBA code which makes an ADO connection to an Excel 2007
file typically looks like this:

'================================================= ==========
' Create the Recorset object and run the query.

szSQL = "SELECT * FROM [Sheet1$A1:A1]"

Set rsData = New ADODB.Recordset
rsData.Open szSQL, szConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

' Extract data from rsData recordset object

rsData.Close
Set rsData = Nothing
'================================================= =========


So, my question is, once I have an open ADO connection, is there any way to
make
another SQL query before running the "rsData.Close" command?? Or, do I
simply
need to close the connection and then run the Open command with a new "szSQL"
string command??

thanks!


You can leave the connection open and run new SQLs whenever you need
them. So then, you could pull data from several worksheets and store it
in separate recordsets if desired.

In this case, you need to close the connection when your project is
shutting down.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc