Using ADO in VB, how do you execute an Access query? I've tried treating it like a stored procedure with no success. Surely Microsoft didn't leave a huge hole like this in one of it's main programming solutions on purpose!
Printable View
Using ADO in VB, how do you execute an Access query? I've tried treating it like a stored procedure with no success. Surely Microsoft didn't leave a huge hole like this in one of it's main programming solutions on purpose!
If you are trying to get the recordset returned by an existing query in Access, this works for me:
Does that help?Code:Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\WINDOWS\Desktop\MyDatabase.mdb"
cn.Open
rs.Open "MyQueryName", cn
' Now rs holds the results of your query
' Do what you want with it here
Set rs = Nothing
Set cn = Nothing
That's way too easy, and it also works. Where is this documented? I looked all over the place and couldn't find anything on it. Thanks for your help.
I used ADO 2.1 Programmer's Reference by David Sussman, WROX publishing