How to call a function on start up

matt beamish

Registered User.
Local time
Today, 14:49
Joined
Sep 21, 2000
Messages
215
I have used a function I found here
http://allenbrowne.com/ser-59alt.html and I have a very simple question on how to run it.

The instructions show me how to run that function (and include subdirectories) by using

Code:
Call ListFilesToTable("C:\Data", , True)

from the Immediate window (with which I remain woefully unfamiliar).

I can now run the procedure from the Immediate Window, but I want to run it either on database start up, or from a button. How do I do this?

Thanks

Matt
 
Matt,

If you create a macro and name that macro "AutoExec" that macro will be run when Access open you applicaiton unless the Shift key is held down when the file is opened. In this macro you can call your function and then do whatever else you might need to do, like opening a form, etc.

You can also place your function call in the "On Open" event of a form that is set to open from the Startup options.

You could also run your function call by placing your statement in the "On Click" event of a command button on a form.
 
Behind a button you would call it the same way:

Call ListFilesToTable("C:\Data", , True)

To run it on start up you can either put it in the load event of form that starts up, or use the RunCode action in an AutoExec macro.
 
To run at databse startup, create a macro named "autoexec". You will have one action in your macro - "RunCode" and the function line will be

ListFilesToTable("C:\Data", , True)

To run this from a form, in the "OnClick" event of whatever button you want to push, add the line

=ListFilesToTable("C:\Data", , True)
 
Thanks for replies, I have it running now. The database is used by up to 20 people, and is split front and back. For the procedure to run on every start up is excessive I think (especially as it is deleting out and then writing a table of several thousand entries each time), but it does need to be done on a daily basis automatically.

thanks again

Matt
 
What I often do in instances like that is create a "utility" MDB that does this process on startup and then closes itself. Then I call that MDB from Windows Scheduled Tasks. That way it runs once per day, no matter how many people run the main program (if any).
 
And just another option is something I've done before where I have a table which gets written to when the function runs. The field is a date field which then the function also checks to see if today's date is there. If it is, it doesn't run, but exits. If the date is not today's date then it runs and then sets the date for today there. Just another way of doing it.
 

Users who are viewing this thread

Back
Top Bottom