Results 1 to 1 of 1

SQL Statement takes too long to refresh

Threaded View

  1. #1
    Registered User
    Join Date
    04-30-2012
    Location
    Massachusetts, US
    MS-Off Ver
    Excel 2003
    Posts
    4

    SQL Statement takes too long to refresh

    Hello,

    I'm writing a script for a database integration project using multiple upload sheets and I need to delete all contents from all worksheets and then refresh all SQL queries before running the conversion scripts that I'm calling from seperate modules (I have a tad bit of OCD when it comes to seperating my scripts) but the problem I'm running into is the script looks for certain column headers. So while the SQL query is still grabbing data, my script is looking for headers that don't exist yet. I've tried multiple wait functions and can't find one that allows the SQL statement to continue while it waits. Any help would be greatly appreciated. Thanks. Sample code below.

    Sub MasterSub()
        
        Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
    
       ws.UsedRange.ClearContents
    
    Next ws
    
    ActiveWorkbook.RefreshAll
        
        Sheets("Products").Select
        Call ProductsModule.Products
        Sheets("BoM").Select
        Call BoMModule.BoM
        Sheets("Category").Select
        Call CategoryModule.Category
    
    End Sub
    Nick

    EDIT Solved. The only way I found the SQL statement would continue to run while waiting is the application.ontime method where the coding looked like this:

    Sub MasterSub()
    
    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Worksheets
    
       ws.UsedRange.ClearContents
    
    Next ws
    
    Application.ActiveWorkbook.RefreshAll
    Application.OnTime Now + TimeValue("00:00:10"), Procedure:="TimeDelay"
    
    End Sub
    
    Function TimeDelay()
    
        Sheets("Products").Select
        Call ProductsModule.Products
        Sheets("BoM").Select
        Call BoMModule.BoM
        Sheets("Category").Select
        Call CategoryModule.Category
    
    End Function
    EDIT Even better, Data Range Properties for the external data import has a box that says Background Refreshing! Unchecked this and everything worked....... figures I missed it
    Last edited by Nrowell92; 05-02-2012 at 01:47 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1