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

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

thelton

New Member
Joined
Sep 5, 2002
Messages
29
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
 

klb

Well-known Member
Joined
Apr 3, 2002
Messages
821
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.
 

Forum statistics

Threads
1,144,274
Messages
5,723,440
Members
422,497
Latest member
dougy99

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
Top