How to run a VB Script from MS Access (1 Viewer)

Shallo9

Registered User.
Local time
Today, 10:51
Joined
Nov 11, 2011
Messages
95
Hello All,

I've written a small VBScript to delete a folder from %Application Data% which is created by my MS Access Application every time the user logs in, so that they don't get a Profile Storage exceeded error.

All is well so far. However, I want this VBScript to run automatically, the moment the user exits/closes the Access Application rather than explicitly running the VBScript.

Any help would be appreciated.

Many Thanks
 

James Dudden

Access VBA Developer
Local time
Today, 18:51
Joined
Aug 11, 2008
Messages
369
I have a 'main' form that is always open so if ever I need to run code when the application closes I do it on the OnClose of the 'main' form.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 03:51
Joined
Jan 20, 2009
Messages
12,856
Why not write the script code in VBA?

Then have it run in the OnClose event as James suggested.

Some developers open a hidden form before anything else exactly for this purpose. When Access shuts down the last form to close is the first one opened so use that form's OnClose Event.
 

Shallo9

Registered User.
Local time
Today, 10:51
Joined
Nov 11, 2011
Messages
95
Okay I'll make it more clear. Every time a user starts my Access Application from either Start Menu/Desktop Icon, A folder (For Ex: C:\Documents and Settings\USERID\Application Data\Database)is created within the users %Application Data%.

Now this folder "Database" cannot be deleted until the user exits the program, so I cannot write the code in VBA (Within the application). Hence the need of a separate VBScript.

I also know Access do not support Multi-threading but I was still wondering if I can use any other program which ignites my VBScript as soon as the Access Application is closed.

I am sorry if I've confused.

Many Thanks
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 03:51
Joined
Jan 20, 2009
Messages
12,856
The old "hold your breath until you die" conundrum.

Your script needs to run continuously while the application is active with a loop checking a flag of some kind that is set by the Access application. This flag can be as simple as the presence or absence of a file. Your application deletes the flag file and the script deletes the application file.
 

Users who are viewing this thread

Top Bottom