Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error '1004'

Status
Not open for further replies.

rss01

Technical User
Oct 10, 2001
125
US
hi,

I have access code that performs opens excel and runs web queries. Not all the time but randomly I will get this error.

Run-time error '1004';
Unable to open
The connection to this Internet site took longer than the alloted time.


Code:
Set dbase = CurrentDb
Set objXL = New Excel.Application
With objXL
    .Visible = True
Set objWKB = .Workbooks.Open(ConWKBK)
Set objWSHT01 = objWKB.Worksheets("DATA")

objWSHT01.Activate

With objWSHT01.QueryTables.Add(Connection:=objRst01, _
        Destination:=objWSHT01.Range("a1"))

        .BackgroundQuery = True
        .TablesOnlyFromHTML = True
        [highlight].Refresh BackgroundQuery:=False[/highlight]
        
        .SaveData = True
    End With

The highlighted code above is where is always errors at. I can hit the debug button and restart the code and everything works fine.

My question is, What can I put in that if this happens to retry (basically what I do when I hit debug and restart the code)?

Thanks,

Randy
 



You are opening an existing workbook, it seems. Then you ADD a query table. WHY? All you need do is REFRESH the existing query table. But first you ought to delete all the unnecessary QTs that you proliferated by your code.
Code:
Set dbase = CurrentDb
Set objXL = New Excel.Application
With objXL
    .Visible = True
Set objWKB = .Workbooks.Open(ConWKBK)
Set objWSHT01 = objWKB.Worksheets("DATA")

objWSHT01.Activate

With objWSHT01.QueryTables(1)
        .BackgroundQuery = True
        .TablesOnlyFromHTML = True
        .Refresh BackgroundQuery:=False
        
        .SaveData = True
End With

objWKB.Save

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yes it is opening an existing workbook. The web query doesnt exist in the workbook, I pass it from access. We use this to download pricing from a website for a market. Each market has roughly 300 unique url's that get priced. So instaed of having 300 existing workbooks, the webquery url is passed each time.

Once the webquery is populated in excel, some code is called from the master workbook and formats the information into a logical format to be imported. back into access.

Hopefully that makes sense.

Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top