Refreshing a query every minutes

deadseasquirrels

Board Regular
Joined
Dec 30, 2004
Messages
232
I have a query shown below:
Code:
Sub Daily_Integration()
    Dim connString As String
    Dim dbsNDF As ADODB.Connection
    Dim dbCommand As ADODB.Command
    Dim sqlString As String
    Dim headerRange As Range
    
    If Not Range("A1") = " " Then
        Range("A1").CurrentRegion.ClearFormats
        Range("A1").CurrentRegion.ClearContents
    End If
    
    Range(Cells(1, 1), Cells(1, 4)).Font.Bold = True
    Cells(1, 1) = "DATABASE"
    Cells(1, 2) = "DK_BOX"
    Cells(1, 3) = "Integrated_Thru(Eastern)"
    Cells(1, 4) = "Money Integrated_Thru(Eastern)"
    
    Set dbsNDF = New ADODB.Connection
    Set dbCommand = New ADODB.Command
    
    connString = "Provider=MSDAORA.1;Password=[pwd];User ID=[uid];Data Source=DKARCH1.WORLD;Persist Security Info=True"
    dbsNDF.connectionString = connString
    dbsNDF.Open
                
    sqlString = "select * from so.v_intg_status_all"
                        
    dbCommand.ActiveConnection = dbsNDF
    dbCommand.CommandText = sqlString
    
    Set dbRS = dbCommand.Execute()
    
    Cells(2, 1).CopyFromRecordset dbRS
    Range("A1").CurrentRegion.NumberFormat = "mm/dd/yy h:mm AM/PM"
    
CleanUpAndClose:
    dbRS.Close
    dbsNDF.Close
    Set dbRS = Nothing
    Set dbsNDF = Nothing
    
End Sub
However I would like to set it up so that it runs this query and refreshes the recordset that is returned to cell(2,1) every 5 minutes or so. Is there a way to do this other than looping through the lines below.

dbCommand.ActiveConnection = dbsNDF
dbCommand.CommandText = sqlString
Set dbRS = dbCommand.Execute()
Cells(2, 1).CopyFromRecordset dbRS

Or do I basically have to do a time delay type thing in a loop and just keep on doing it forever? How do I keep time anyway?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Is there not an option when you right click the query on the worksheet and select Data Range Properties.

I think it's in the Refresh Control section.
 
Upvote 0
Why not record a macro when you select the option I talked about?
 
Upvote 0

Forum statistics

Threads
1,215,242
Messages
6,123,830
Members
449,127
Latest member
Cyko

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top