Connecting Questions on Querytables

A

Accesshelp

Hello all,

I have two querytables in my Excel worksheet "Sheet 1" that connect to an
Access database. Since I have two querytables, I only want to run one of the
two. So I use the following code for my command button:

Worksheets("Sheet 1").QueryTables(1).Refresh

Somehow, when I click on the button, the query would not run. In order to
run that query, I have to go into Data>Import External Data>Edit Query to
run. What I have been noticing is after I go into Edit Query, subsequent
clickings on the button will run the query, without going into Edit Query.
When I close the file and open it next time, I will again have problem
running the query when I click on the button, unless I go into Edit Query.

Does anyone know what causes to happen? Do I have the code correct? How
can I fix that problem? Is there a way to find out what querytable number is
for the query that I want to run?

Thanks.
 
A

Andy Smith

Check the query's properties. First, you should use the name of the query,
not the
number 1, in your code, e.g.:

Worksheets("Sheet 1").QueryTables("MyQuery").Refresh.

Second, see if the query refreshes in the background, every few minutes, or
on file open -- if you're refreshing it in code, none of these should be on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top