View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Chuck[_11_] Chuck[_11_] is offline
external usenet poster
 
Posts: 58
Default Get External Data

On Sat, 4 Oct 2008 20:36:01 -0700, FSt1 wrote:

In line comments.

hi
adding a new query and refreshing an existing query are two different things.
the code you posted is for created a new query each time it's run.
you only need to do that once. after that all you need to do is refresh.
a sub like this is what i use and is all that is needed to refresh.
Private Sub CommandButton1_Click()
Range("A1").Select
Range("A1").QueryTable.Refresh BackgroundQuery = False
MsgBox "refresh complete"
End Sub

It's been a very long time now, but I believe all the previous data was deleted
and replaced with new data each time the Excel file was opened. At this point
I'm really confused. Why does this macro run just by opening the Excel file?
I don't have an autoexec macro. The sub is Sub GetMDBdata(). I do not click
a command button. Open the file and it runs.

you say you ran this code for a year???? i don't see how you didn't get this
message a year ago unless you are creating a new query in a new file each
time.

I'm running the query each time the Excel file is opened. I am not creating a
new query.

if your are creating a new query each time, remove all lines in the code
that refer to "refresh". creating and refreshing in the same sub is double
duty and redundent and may be the source of your error.

I commented out all lines with "refresh" The macro runs without any error
messages, but it doesn't get any data either.

Regards
FSt1