472,111 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

Access startup - can you run code on database open?

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
  5. If MYPATH = "<server_name>\<path>\<file_name>" Then acCmdOpenStartPage
  6.      MsgBox "NoNo", vbOKOnly, "!!!!!!! ILLEGAL COPY DETECTED!!!!!!!!"
  7.      End If
  8. End Sub
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
4 43686
3,532 Expert 2GB
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
Linq, you are a gem!

Thank you so much =)
Sep 2 '07 #3
I can't find that reference in the help for Access2007... is it still valid?
Aug 3 '11 #4
32,497 Expert Mod 16PB
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.

Similar topics

2 posts views Thread by Nicolae Fieraru | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.