I am trying to automate an excel report so that it automatically posts a SQL query then saves the file every 24 hours. Currently I can do one or the other (post sql or save) but I cannot run both at the same time.
So far, I have an ODBC connection between my excel file and my MS SQL database and have the SQL queries refreshing every 1440 minutes.
I also have a VB timer set to run every 24 hours to save the workbook every morning. The timer starts when I click a button. Here is the script I use for that
Sub Save()
ActiveWorkbook. Save
timer1
End Sub
Sub SaveName()
ActiveWorkbook. SaveAs Filename:="C:\. .."
timer1
End Sub
Sub timer1()
Application.Wai t Now + TimeValue("24:0 0:00")
Save
End Sub
Private Sub CommandButton1_ Click()
timer1
End Sub
However, when I click the button to run the timer it slows everything down so that my MS SQL query timer does not count down.
My question is how to get both of these to work at the same time. Should I run the SQL query within VB as well so both functions use the same timer. If so, how would I do that. If I can figure this out, I will be able to run several reports that update, save and e-mail themselves out every day, week, month etc...
Onthefly
So far, I have an ODBC connection between my excel file and my MS SQL database and have the SQL queries refreshing every 1440 minutes.
I also have a VB timer set to run every 24 hours to save the workbook every morning. The timer starts when I click a button. Here is the script I use for that
Sub Save()
ActiveWorkbook. Save
timer1
End Sub
Sub SaveName()
ActiveWorkbook. SaveAs Filename:="C:\. .."
timer1
End Sub
Sub timer1()
Application.Wai t Now + TimeValue("24:0 0:00")
Save
End Sub
Private Sub CommandButton1_ Click()
timer1
End Sub
However, when I click the button to run the timer it slows everything down so that my MS SQL query timer does not count down.
My question is how to get both of these to work at the same time. Should I run the SQL query within VB as well so both functions use the same timer. If so, how would I do that. If I can figure this out, I will be able to run several reports that update, save and e-mail themselves out every day, week, month etc...
Onthefly
Comment