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.Wait Now + TimeValue("24:00: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
10 8477
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.Wait Now + TimeValue("24:00: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
Excel has an Autosave add-on that comes with it, why not use it. Should be listed under tools, if not you'll need the disk to add it.
That is what I originally tried, and it works but the autosave feature saves it as an .xar file and it saves it like a hidden file which prevents my re-occurring e-mail software program from recognizing it. Using the Autosave feature would be my first choice if I could figure out a way around this issue.
Ok, I re-read your post, and you have the Excel file Updating / inserting the Excel changes to the MS Sql Database every night, correct?
Why not just perform the updates when they're made. I created one at work that uses ADO and when you leave a cell, updates that records field
If I do not have a value in the 1st column then that indicates a new record so it does an insert to the table
Actually I have it the other way around. I have an excel spreadsheet that is pulling info from my MS SQL database everynight and posting the results in the spreadsheet (and it erases the results that were their the day before). So my question is, how do I then save the changes from the new query after the update took place so I can e-mail out the new figures.
Thanks for your help by the way....
Actually I have it the other way around. I have an excel spreadsheet that is pulling info from my MS SQL database everynight and posting the results in the spreadsheet (and it erases the results that were their the day before). So my question is, how do I then save the changes from the new query after the update took place so I can e-mail out the new figures.
Thanks for your help by the way....
We both learned on this one.
Create a module with this procedure in it -
Public Sub SaveData()
-
ThisWorkbook.Save
-
MsgBox "Saved", VBOkOnly, "Data Saved"
-
End Sub
-
and in the worksheet add this -
Private Sub Workbook_Open()
-
'This will run the code 1 minute after the worksheet is opened
-
Application.OnTime Now + TimeValue("00:01:00"), "SaveData", , True
-
-
'Or Use this to set a time, here it is 1 PM
-
' Application.OnTime TimeValue("13:00:00"), "SaveData", , True
-
End Sub
-
-
Hey, I think this will work! But I must be missing something because as it tries to save I get this error:
The Macro:"C:Documents and Settings\....'!SaveData' cannot be found.
Sorry, I am fairly new with VB so I am probably missing something simple.. any idea?
Hey, I think this will work! But I must be missing something because as it tries to save I get this error:
The Macro:"C:Documents and Settings\....'!SaveData' cannot be found.
Sorry, I am fairly new with VB so I am probably missing something simple.. any idea?
In the VBA Editor add a module, I call mine Utils since I usually add other functions and subs to it to do different things. Then place the "Public Sub SaveData()" I gave you there, not in the worksheet area. Then it should see it.
This is awesome, it works perfectly!
Thanks!
This is awesome, it works perfectly!
Thanks!
No problem, glad to help, and that was a method I was not aware of so I learned something as well.
Quick question, will this loop the time so it saves it every day at the same time without me having to re-open this?
I'm glad you learned as well. The cool thing about this set up is that I now have about 25 excel reports that automatically update themselves every day/week/month and e-mail themselves to the business owners at a specified time, so I don't have to touch them.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ryan |
last post by:
I came across a situation that I've been unable to explain and was
hoping somebody had an answer:
I had written an update query which was taking about 8 seconds to run
and considered it too...
|
by: Carl |
last post by:
Please can anyone tell me how I can create a macro to save the results
of a query as an excel file? The query is called Student List and I
would like to save it to "My Documents".
We have had...
|
by: Adam Louis |
last post by:
I would like help resolving this problem. I'm a novice who's been
hired to query a hospital database and extract useful information,
available to me only in a dynamically generated, downloadable...
|
by: Nicolae Fieraru |
last post by:
I have two tables, they contain:
Table1: ID1, Name1, Address1, Purchase1
Table2: ID2, Name2, Address2, Purchase2
I need a query which creates Table3 with content from Table1 and Table2.
The...
|
by: Smartin |
last post by:
Using Access 97
I am trying to create a form that allows for user entry of search terms
and displays a table of results. I thought I could accomplish this using
a subform but it isn't quite...
|
by: Macroman |
last post by:
MS Access XP, running on Win XP, Processor 2.4Ghz , 512Mb RAM, 40Gb Hard
drive
Table 1 has 167,000 records and contains the following fields
tblone_custID
tblone_easting
tblone_northing
...
|
by: eighthman11 |
last post by:
Hello everyone. I have a table linked to an excel spreadsheet. I have
an append query based on this link table. I receive an error when I
run the append query "numeric field overflow". I have...
|
by: Nathan Guill |
last post by:
I have an interface that works with an Access back-end. I would like to
store and/or load user defined query strings per each user (i.e. no user can
access another's queries). The idea I had was...
|
by: Wayne |
last post by:
I'm trying to automate the export of a query to a text file using
code. If I export the query manually I get the exact result that I
want i.e. If I select the query then choose File/Export from...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |