View Full Version : MS Access 2000 startup code

18-01-2005, 04:56 PM
I want to execute some code when a particular Access 2000 application is started. I realize I can specify a startup form and have some code attached to that, but I would like this code executed even if the user presses [SHIFT] to bypass the startup stuff (and so also the initial form). What I am trying to do is to initialise some global variables with default values from a table.

Any ideas, anyone?

19-01-2005, 12:46 PM
See the 'Set Startup Properties from Visual Basic' topic in VB Help, and the AllowBypassKey property. You can use a AutoExec macro that runs when the database starts.

Also some info here...http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acstartupoptions.asp

19-01-2005, 02:09 PM
Thanks Parry, that certainly points me in the right direction. As usual, what I want is something slightly different. I wanted to allow the use of the SHIFT key, but still execute some startup code. If I read it correctly, with AllowByPassKey it is all or nothing. SHIFT will bypass the autoexec macro and the other startup options unless AllowByPassKey is set false, in which case SHIFT has no effect. It looks like I might have to put my startup code into the OPEN of the initial form and warn the user that SHIFT will mean it doesn't get executed.

Looking at the stuff in the VB Help and the MSDN page you pointed me to, it is not clear to me where you put the code that is used in the examples. The VBhelp says "If a startup property hasn't been set previously, you must create it and add it to the Properties collection of the Database object. Where do you do this? In the autoexec macro?

My problem is that although I have done tons of programming (as a living), my Access skills are all self-taught, and I find it really hard to find out stuff like this - especially by reading the VB Help! :confused:


19-01-2005, 04:02 PM
Hi Tony know what you mean. Im familiar with the Excel object model but things Im used to being there (like lots of application level events) are not readily apparent in Access. Sometimes you have to create class modules for new properties but rarely as most things are built in and available.

Anyways look at this thread here http://www.tek-tips.com/viewthread.cfm?qid=843828 and in particular the code in the last post by Binnit dated May 19 2004.

I think you only need the code for the cmdLockDB_Click sub and ChangeProperty function as the rest is in regards to password setting. Run the cmdLockDB_Click sub and this will set the AllowBypassKey property to false which I believe disables the effect of shift-clicking when opening. Note this only has to be run once. When calling the ChangeProperty function the last argument indicates whether this property is on or off.

eg this will turn back on Shift+Click...
ChangeProperty "AllowBypassKey", dbBoolean, True