View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Andy Smith[_2_] Andy Smith[_2_] is offline
external usenet poster
 
Posts: 50
Default Connecting Questions on Querytables

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.

--
* Please click Yes if this was helpful *
Andy Smith
Senior Systems Analyst
Standard & Poor''s, NYC



"Accesshelp" wrote:

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 DataImport External DataEdit 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.