I am trying to utilize windows task scheduler to distribute Access reports to End Users in my company.
All I am doing is triggering a macro that runs code from a module which exports a report to a PDF, prints it out, then exits access.
DoCmd.Quit acQuitSaveNone
That's what I've been using at the end of my code in VBA to close access after running a macro.
When I manually run the macro it works fine, but when scheduled on a task, it gets held up a lot and stuck.
I've checked event viewer to try and find any Microsoft Office alerts but do not see any.
It appears that Access is unable to quit many times when running through Task Scheduler. Would there be a VBS I can run, say, 5 minutes after the task to close down the .accdb file and MSACCESS.EXE or is there something I can do to make these Tasks actually work??
It seems maybe when running in the background through task scheduler.. the code is getting ahead of itself and trying to quit at the same instance that it is finishing the output to the printer, causing it to seem "busy" and unable to actually close?
I have an entire domino of code that shoots off after this but it stops dead in its tracks when it cannot finishing closing access.
Any suggestions?
Thanks,
Ian
Here is the gist of what I would do, I am just addressing the print on open and quit actions. You may need to tweak to ensure that you have validation etc in place.
First, make sure that your report has a default printer specified. (Report design-->Page Setup-->Page-->Use Specific Printer and then select your printer)
Create an Autoexec (auto execute) macro, this macro will be saved with the name Autoexec. Macros named Autoexec executes when Access is opened automatically. Note that once you have this macro, it will run each time you open Access, to prevent it from running, hold down the shift key and then open Access, this bypasses the Autoexec
First action in your Autoexec Macro is OpenReport and set the View to Print (report is printed when opened)
Next action in your Autoexec Macro is QuitAccess with options set to SaveAll.
When you run an application from the scheduler, it runs with different credentials. You want to make sure that you choose the appropriate options here.
Fixed it. Very glad as I've seen many with this issue and hope this gets to them.
If anyone has any issues regarding access macros and task scheduler and this doesn't work - I'll be happy to help as best as I can as the frustration of wanting to remove administrative tasks through automation that don't work out is just terrible.
Since I needed the task scheduler to wake the computer up, log me in, and open access databases on network drives that reference SQL servers.. there was a couple things I had to make sure were set up.
First is trusted locations. Any network drives you are access should probably be in the trusted locations.
Secondly, my last command on the macro is DoCmd.RunCommand.Close (I believe.. if im wrong Ill change tomorrow when I'm back in the office)
Third, use the root path to the network folder and not a mapped drive as they may not map when your logged off... so instead U:\file path... would have to be \computer1\filepath\ etc..
This path should be made with all linked tables or databases among the network especially if you have code calling for those files.
Fourth, I ended up having to do it the less preferred way and have a folder called "accessjobs" where I put shortcuts to Access Macros which triggered code and simply ran that path in task scheduler with "start in:" the folder the macro shortcut is in.
Fifth I had to run with highest privileges, and selected "run whether user is logged on or not"
A couple of these things may be coincidental that they work, but I am not about to spend even more time with trial and error to see which settings are benine as I spent TOOO long figuring this all out. But now it is solved and the sky is the limit now!
Thanks for the help!
Ian
Related
I'm doing one social project and use only Acess/Office 2013 available, and trying to send email reminders for some event based on calculated column [Due_date] -[Today] < 10 days, my customers most likely won't open Access every day, so I'm wandering if any option exists in Access to schedule this job/check let say every 8am ? Is it basically possible with only Acess ???
*I also deal with actual autoemail VB script, but without solving scheduling task it probably wont' work anyway.
Appreciate your feedback. THanks
Dai
There's no scheduler built-in to Office specifically... but Windows has one.
Windows' Task Scheduler can be used to schedule code to run in Office applicationss using Office's command-line options
You should be able to find the task scheduler in the Start menu b hitting the and typing task, or by pressing +R and then typing taskschd.msc in the Run box.
There are numerous options for "how" you want to schedule your tasks. For example I have an Access DB that auto opens every 8 hours (waking it from sleep if necessary) to perform a task, and other that runs at logon if it hasn't run in the last 12 hours.
more Information:
Office.com : Command-line switches for Microsoft Office products
Office.com : Command-line switches for Access
(/x and /cmd are especially useful for this.)
Windows Dev : Task Scheduler
I have used Task Scheduler, and similar, to open many Access DB front-ends at various frequencies from 15 minutes to a week.
It goes like this: open file, autoexec macro then opens a Form, Form_onOpen executes whatever code I want - including DoCmd actions to delete table records, create new tables, run reports, export to Excel, export as acrobat files, etc. and then save and Quit. Very useful for overnight mining SQL Server-based work management systems.
I am reading about options that will allow me to run a macro without locking down my session of Access until it is done running. I have some VBA macros for Access that execute SQL SELECT and UPDATE statements and can take almost an hour to run. This currently locks down Access for me until it is done running.
I am seeing what options there are so that I can the macro and and still use Access while it finishes running the report in the background. I came across DoEvents() as an option, but just about everything says not to us it. So what are some good alternatives?
DoEvents has its uses, e.g. if you have a long running loop and want to give the user a "Cancel" button that he can actually click.
But in your use case the best option is:
Make a copy of your frontend database
Run your VBA code in one instance of Access with the first frontend
Start a second instance of Access, open the second frontend, do whatever you want (well, you shouldn't do something that locks tables used by the first instance).
So I started with the Access contact database template and have been building up from there. There is a functionality in which by clicking on the ID number in the Contact List, it should call up the form to edit the details. I have made no changes to this code, and have even tried recopying it from the template from scratch.
However I am getting the error "A problem occurred while Microsoft Access was communicating with the OLE server or ActiveX Control." It is telling me to restart the OLE server and try the operation again.
I have an old version of the database saved, and it runs fine over there. It just is something within my code here.
Any guidance would be appreciated.
All of solutions I found online was not working for me.
Found that only rebuilding damaged form from scratch help me to solve this issue.
W10, Office 2016.
I have ran into this error three times in my database. Each time to fix it I simply just open a new blank project and import everything from your old project into your new project.
This might sound like a large undertaking basically you just go into the new project and select "Import Access Database". Then just run through the wizard selecting everything in your current database. Click okay and let it run for a few minutes.
This has fixed it for me every time I have run into your error. I suspect it is just something to do with corruption.
My programs also run into this error sometimes.
I have recently noticed that the error most often occurs on UNBOUND forms (forms without a RECORDSOURCE).
What I have done most recently for these forms is the following:
Add "some" table (I usually take a Config table with just one record) as the RecordSource.
Compile the program code (this usually goes well, even before the fix!).
Save the form
Open the form. This should work fine now!
Remove the form's RecordSource, recompile and save again.
The form should still work fine!
I am trying to generate the database scripts(tables,triggers,views,procedures) in sql server 2008, all of sudden the scriptting wizards hang up at the end state saying that scripting is completed but the close button never enable, if i stop this some of the tablels are missing, please advise
Install earlier SSMS version.
For me bug was at 15.0.18358.0, changed to 15.0.18338.0 and the wizard started working.
If the wizard says "0 Remaining", this means it has determined all the objects that it needs to script, and is writing them out to your destination. If you are writing to a file, go to that file location in Windows Explorer, and keep refreshing the view. If the file keeps growing in size, this means everything is fine and the data is still being written. Be patient, and eventually the process will finish and the Close button will become enabled.
Running Access 2010 on Citrix against a SQL Server 2008R2 backend. Occasionally my users will get an error reading:
The expression On Change you entered as the event property setting produced the following error: Overflow.
* The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
* There may have been an error evaluating the function, event, or macro.
Once a user gets this error during a session, he will continue to get it until he logs out of the database front end. He can then immediately relaunch the Access front end and go do whatever it was he was attempting to do. The On Change portion will vary in event type (sometimes On Click, sometimes After Update, etc), and it will happen on different forms, but the fix is always to exit the DB then get back in and everything just works fine.
The more I learn, the more I'm starting to believe that it's got something to do with the Citrix enviornment that we're in, but I haven't been able to pin anything down.
I've seen the suggestions to copy the form, and to start with a new DB and import everything. I've done these and it hasn't really helped - i.e. this is random enough that I don't know if the frequency of issues decreased significantly after the change.
Does anyone have any additional suggestions of what I can do in my Access code?
Does anyone have any experience with this setup and have some Citrix or SQL Server tweaks that I might be able to pass along? (I don't know if our IT people will listen or try to work with me on it, but it's worth a shot.)
I'm frustrated with the randomness of this, and I hate telling my users there's nothing I can do about it, but at the moment, I'm completely stumped.
Thanks,
FreeMan
Edit - Additional details...
the users are running a compiled .accde
they are all running from a common .accde file
this is still happening for a few users to whom I have given their own personal copy to run
The goto fix for random weird stuff happening in Citrix is to disable hooking. Hooks get injected into every process running in a Citrix session, so they could be screwing up something in Access. You can configure registry entries to exclude Access from being hooked:
http://support.citrix.com/article/CTX107825