By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,154 Members | 2,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,154 IT Pros & Developers. It's quick & easy.

Access startup - can you run code on database open?

JodiPhillips
P: 26
MS Access2000

Hi everyone,

I've searched the forums for an answer to this question and nothing jumps out at me.

When a database is opened I want to automatically run code (at start-up) that compares the path of the opened database to a specific path (where the original database is located). This is for security reasons - I need to know if the original database has been copied without authorisation. Due to network issues I cannot use intrinsic MSAccess groups and permissions and have setup security that operates from within Access - ie log in table, and of course the original database is vulnerable to being copied.

This is the very bare bones - very basic code for the comparison (don't laugh - in this format its just for testing to see how I can get it to load at startup - it works fine though).

Expand|Select|Wrap|Line Numbers
  1. Sub MYPATH()
  2. Dim MYPATH
  3. MYPATH = CurDir
  4.  
  5. If MYPATH = "<server_name>\<path>\<file_name>" Then acCmdOpenStartPage
  6.      MsgBox "NoNo", vbOKOnly, "!!!!!!! ILLEGAL COPY DETECTED!!!!!!!!"
  7.      End If
  8. End Sub
  9.  
StartPage opens my log-in splash form (frmLogSplash) where users enter their userid and password (this compares the password stored in the log-in table and if its good then they continue to the next user form - if its not after three attempts the application closes).

The startup options in Access only allow me to open a form, load a menu bar, a shortcut menu, or set the bypass key.

So to get to the point of this post - can you script an autorun on open type event in Access? That is can my dir/path script be made to run each time a database is opened? If so, can anyone point me in the right direction on how to go about this? (I'm happy to have a go at working out the scripting myself, just need some guidance on how to). I'm also very willing to be guided on improving the above code (remember though that this is just a two second job for testing)

Thanks everyone =)
Sep 2 '07 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
Goto Access Help and enter the search term Autoexec. Then click on Carry out an action when my database first opens. This will tell you about the Autoexec Macro, a special macro that runs automatically when a database opens. You'll need to put your verification in a function, then in the Macro builder under Action choose Run Code then place the function name in the appropriate box.

Linq ;0)>
Sep 2 '07 #2

JodiPhillips
P: 26
Linq, you are a gem!

Thank you so much =)
Sep 2 '07 #3

P: 6
I can't find that reference in the help for Access2007... is it still valid?
Aug 3 '11 #4

NeoPa
Expert Mod 15k+
P: 31,616
Probably not Shannon.

Look instead at Tools \ Startup \ Display Form/Page. If you enter a valid form in there you can ensure the form has code in its FormOpen event procedure.
Aug 4 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.