Triggering an mdb query on server - ms-access

I have a Microsoft Access MDB file on a website to which an ASP classic code adds rows.
How do I create a query/module that will run every time I add a row or automatically once a day?

If you're looking for something to run when a row is added, you're looking for "triggers" - which is not available in Access*. You find that sort of thing in proper RDBMSs like SQL Server, MySQL, etc.
If you're looking for something to run once a day, you could create a small VBS/PowerShell/etc. script and set up a scheduled task on the server to run it at an appropriate time.
You could also run the query in response to a page. If this is something that you want done after insert, then you can append the appropriate code to the end of the page or have it run as a part of the "success" page (if you have one).
* Unless you are using a .accdb (Access 2010 and later) file and the appropriate drivers. Then it appears you can use Event-Driven Data Macros to get the same effect. Thank you Gord Thompson.

Related

Design View in Access not bringing up an append query?

I am updating a MS Access away from access. There are some Append Queries that the design view will not come up at all. I read somewhere that if the append is extra old you just need to save the DB as an older version. However, that also fails to do anything.
I am using O365 Access with a 2007-2016 file format DB. It has been upgraded multiple times over the years I would assume it might've started as a 2000 DB.
What can I do to see the design of the append?
If you open the Visual Basic IDE (Alt+F11), and then open the Immediate Window (Ctrl+G), you should then be able to enter the following expression on a new line in the Immediate Window (changing Query1 to the name of your query) and press Enter to view the SQL associated with the query:
?CurrentDb.QueryDefs("Query1").SQL
You could then inspect the tables/queries referenced in the SQL and see if anything is amiss, or copy the SQL to a new query to see if it exhibits the same behaviour.

VBA DoEvents() in Access or an alternative

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).

Access - Prevent Database Size Growth

I am using a MS Access 2013 light application that was developed by a third party. I did not do the coding/design/management of the project, but I am responsible for implementation for my team. I also do not have the option of switching to another solution, but I do have access to the vba code so I can make tweaks to clean up their mess.
My problem is this:
Set up application with my data (a-ok).
Run the built in, fairly complex third party macro.
For most cases, things are just fine... but when running it on a
larger dataset the filesize of the Access file exceeds 2GB and the
entire operation fails.
On fail, the process has to be restarted. For the same data set,
it fails each and every time it reaches approximately 55% complete.
I am unable to complete my work because of this. :|
Solutions tried:
Compact and repair - Fine when it fully executes, but the issue is that it reaches 2GB while the macro is running and cannot be interrupted.
Splitting the database - Splits OK, but doesn't fix issue.
Attempting to trigger a compact and repair inside the macro during the loop - Fails because Access cannot lock the database.
Desired solution:
A way to prevent the file growth/bloat while the macro is running. Either through a compartmentalization of the process or through some other wizardry I am unaware of at this time.
A solution that does not require extensive reconfiguration of the underlying code. I can deal with inefficient - so long as I can fix this issue for this one instance (1 critical error in 44 runs of different data in the database.
Any help?
I would recommend compact on close for easy dirty solution
On the File tab, click Options.
In the Access Options dialog box, click Current Database.
Under Application Options, select the Compact on Close check box.
ADVANCED SOLUTION
The other solution requires splitting the database.
After splitting you have another option.
Use the front with a sql server (check which version is suitable for you, I think the lite (free) version is enough to start with if you don't expect a hige amount of data)
Split the database
Install sql server (mysql or sql server express edition)
Create all tables in the sql server
Link the front to the sql server
I think davejal pretty much nailed this one.
If you have a handful of really large tables, you can put those into another Access DB, and make a link to those.
https://support.office.com/en-us/article/Import-or-link-to-data-in-another-Access-database-095ab408-89c7-45b3-aac2-58036e45fcf6
The 2GB limit is per DB.
Or, upgrade to SQL Server Express for free, and use Access as a front end to that SQL Server backend.
SQL-Server Backend, MS Access Frontend: Connection
Here's a link to get SQL Server Express.
https://www.microsoft.com/en-us/download/details.aspx?id=42299

Access "repair" breaks a slightly complex query

I have an application that creates an Jet database at run-time, and imports ~100k records so that I can make use of the indexing for performance reasons (1 minute versus nearly 10 when not using a Jet database).
The database is created using ADO Extensibility in Excel, and everything works just fine. However, my issue comes whenever I then open the MDB file in Access front-end, it automatically starts to "repair" the database.
The data is still fine after the "repair", however my main output query can not then be viewed in Access as it tells me it cannot represent the joins, and if I then view it in SQL the required joins are not there, and the query can no longer run. This still happens if I let it get "repaired" but do not open that query, i.e. it is the "repair" that breaks the query, not the act of trying to view it in Access. The funny thing about this is that I used the Access GUI query designer to construct the SQL as my life is too short to worry about it's crazy bracketing style, but it then later decides that it's too complex for itself??
Also, nothing else appears to be affected so I can only assume it's this one query it doesn't like.
This isn't a deal-breaker for me as my fix is to make the MDB hidden and advise users who can see it not to open it.
However, I would really like it if the database could be opened and I didn't have to hide it away like that. Therefore, my question is whether there is any way to prevent the MDB being "repaired" automatically?
Thanks!
Microsoft Access is "repairing" the file when opened because it is missing some tables that are specific to the Microsoft Access user interface. Since you created the MDB file directly using OLEDB with Microsoft.ACE.OLEDB.12.0, these tables are not present, and must be created when Access opens the MDB the first time. There are several ways you can circumvent this:
1) Name the MDB something other than .mdb - e.g.: MyAccessDatabase.mad - this will prevent Windows from using Microsoft Access to open the file.
2) Use COM+ to open an instance of Microsoft Access, and have it create the .MDB file. This .MDB file will then have all the necessary tables present and will not need to repair the file.
FYI, whenever Microsoft Access opens an MDB that needs repairing in this fashion, it will inspect all the QueryDef objects for invalid SQL and correct them as necessary. This is why your "complex" query is breaking.

Access 2003/2007 Query contents wiped

Has anyone else come across a situation where the contents (SQL statement) of an Access 2003 or 2007 was completely wiped (the Query object still exists, the inner SQL does not)?
Does anyone know what causes this?
I've just had this happen to me again. 2 queries run from a Macro's OutputTo actions to generate 2 Excel files. I ran the Macro a few times then suddenly no more SQL statement in both Queries.
No, I've never seen this happen. And I've read pretty much all the postings in the Usenet and Microsoft newsgroups mentioning corruption for the last ten years or more.
But I'm wondering. Do multiple users share this MDB? We've had a few bizarre postings with respect to Access 2007 losing VBA code.
I have accidently done this in VBA code in MS Access by creating QueryDef object whose name that matched an existing query.
Yup I've had this happen in a 2003 database - I thought perhaps the database had been corrupted so I rebuilt it from scratch this time using Access 2010, but it has just happened to me again. Macro / button has been working as expected for months, but after I changed 1 line of VBA code in a completely unrelated part of the application (setting a field to null instead of ""), this query wiping has started again.
I run a macro triggered from a button which outputs the results of a SELECT to a file. I've worked out the specific steps I can take to trigger the Query being wiped out, however if I check the query still exists in between each step then the query doesn't get wiped! Obviously this is not a solution for the application users.
I have found in another stackoverflow question Weird Bug: "DoCmd.OutputTo acOutputQuery" is deleting the query a work around I am going to try - change the built-in macro ExportWithFormatting to run code instead and restate the SQL before running the output command.