VBA to Add (Save) & Remove a Query in an MS Access DB within Excel with ADO?

bs0d

Well-known Member
Joined
Dec 29, 2006
Messages
622
I'm creating a workbook to query data from an Access database. Part of the process to get the data I need, requires creating one query (A), and then creating a query (B) to the query (A). I've not come across the need to save a query (from Excel) to Access before.

I'm sure this can be done, can someone show me how (ADO?) And also how to Remove it when you're done?

If you have multiple users, would it make sense allowing each of them to create and deleting queries? Each user could be requesting different criteria, so the request is unique to them. I planned on adding their username to the query name to keep it unique. Thoughts?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
You normally dont do it that way. You build your queries and keep them, and keep using them. Not make 1 , then delete it.
You can just build your 'query' on the fly as an SQL statement in Excel..no need to build /remove the query.
 
Upvote 0
I understand that, but I need to query the results of a query. How can I do that on the fly without saving the initial query for the second query to reference?
 
Upvote 0
If its a simple join, you can do sub query using the IN command. See any Find Duplicates query made by the wizard.

If not, you can build your query defs. (lookup querydefs)
qdf1.sql = "select * from table"
qdf2.sql = "select * from q1"

then get the recordset from qdf2.
 
Upvote 0

Forum statistics

Threads
1,215,757
Messages
6,126,693
Members
449,331
Latest member
smckenzie2016

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top