Running a saved query

mlopes1

Board Regular
Joined
Jul 14, 2002
Messages
114
This is probably a simple question, but I looked through all the help screens and could not find a direct answer for this.

I have a query that I designed using Microsoft Query. It pulls data from Access. I have it saved as Query1.dqy

I would like for this query to be run whenever a certain button is clicked and certain criteria are met. So for the macro assigned to this button I have some if statements.
What is the VB I need to run the query inside the If statements? I can't find how you refer to and run an already saved query. All the info seems to be on defining a query and then saving/running it.

Example

Button_click()

If conditionA = true then
run Query1
Else
do something else
End if



Thanks in advance

Mark
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Instead of trying to run a saved query in VB, why don't you open MSQuery and then view SQL statement, then copy and paste the SQL statement in you code.

Good Luck,Trent
 
Upvote 0
Have you tried recording a macro to run the query?


You can then attach the macro to a button on your toolbar or create a button in your spreadsheet.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

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