Query Error

C

Chad

I get this error:
Run-time error '-2147417848 (80010108)

Automation error
The object invoked has disconnected from its clients

Here is my code. It crashes on the .Refresh BackgroundQuery:=False

Sub LoadAssays()
With ActiveSheet.QueryTables.Add(Connection:= _
"FINDER;\\Server1\data\Engineering\Assay.dqy", Destination:= _
Range("A1"))
.Name = "Assay"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub

Here is the situation. I run it once and it is fine. It loads everything
into a spreadsheet. I close the spreadsheet and then run it again and I get
this error. Do I need to 'close' the connection so I can re-establish it?
If so how do I do this.

Thanks a bunch, everyone here are a great help!
Chad
 
F

FSt1

hi,
this code adds a query. you need only to run it once.
after the query has been created all you have to do after that is refresh
the query.
i am quessing but i think that you get the error becasue you are trying to
create a new query on top of the old. and that is were the conflict occures.
try this

Sub RefreshQuery()
activesheet.range("A1").QueryTable.Refresh BackgroundQuery:=False
end sub

i always recommend that brackground query not be run perticularly if you are
going to be processing the data that the query is refreshing with more code.

regards
FSt1
 

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