VBA alternative for autoexec macro?

G

Guest

Is there a VBA alternative for the autoexec macro?

I have several databases I've created and I want to prevent unauthorized
persons from opening them. Currently I use an autoexec macro that fires a sub
Main, it evaluates some criteria and quits if the criteria is not met. I have
set the allowbypass keys property to false to prevent someone from holding
down the shift key.

My problem is I have a tendency to forget to put the macro in the file
before I make the mde. (I also don't care much for macros). It appears there
isn't a way to create a macro via VBA so I can't build myself a little helper
function to create the macro. If I can create a macro from VBA in Access 2000
please tell me how or point me to a web site.

So is there an undocumented startup property I can set?
Any way to get the startup options to expand to public routines instead of
being limited to just forms? VB6 gives the option of using a modMain this
way, I'd love to be able to do that. And don't suggest switching to VB6 it's
not an option. :-(

Or am I stuck with a longer check list when I deploy something?

Thanks
Mark
 
G

Guest

Hi, Mark.
Is there a VBA alternative for the autoexec macro?

Yes. One usually uses a start up form to run the application's start up VBA
code.
I have several databases I've created and I want to prevent unauthorized
persons from opening them.

I hate to be the bringer of bad news. One can set permissions on Access
databases, but one cannot make them secure, so your goal is unachievable.
Someone with the desire to do so can open your Access databases. All one can
do is set the hurdles for doing so as high as possible.
I have
set the allowbypass keys property to false to prevent someone from holding
down the shift key.

Unless you have also implemented User-level Security on this database and
added the extra parameter to the property when you created it, anyone can use
VBA code to reset this property.
My problem is I have a tendency to forget to put the macro in the file
before I make the mde.

Fortunately, there are many other forgetful people in the world. ;-)

First, ensure that no one else has the MDE database open, because you will
need exclusive access. Then open a database file that already has the
Autoexec macro that you want the MDE file to have (or you may create the
macro from scratch in any other database). Right-click on the name of the
macro in the Database Window and select "Export" from the pop-up menu.
Navigate to the MDE file and select it. When the "Export to" dialog window
pops up, select the "OK" button to export the Autoexec macro to the MDE file.

Voila! No one will know that you forgot to put it in there beforehand
(except those sharp enough to check the creation date).
So is there an undocumented startup property I can set?
Any way to get the startup options to expand to public routines instead of
being limited to just forms?

No. Instead of using an Autoexec macro, you're much better off using a
start up form that either contains the start up VBA code in the form's
OnLoad( ) or OnOpen( ) events, or else uses these events to call the start up
code located in public procedures. If you are worried about unnecessary
forms for the users to be confused with, the form doesn't need to be visible
to the user when the code is running during start up.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
S

Stephen K. Young

My problem is I have a tendency to forget to put the macro in the file
before I make the mde. (I also don't care much for macros). It appears there
isn't a way to create a macro via VBA so I can't build myself a little helper
function to create the macro. If I can create a macro from VBA in Access 2000
please tell me how or point me to a web site.

In your programming tools, you can manually create a macro for startup, but
save it with a different name like "Autoexec_For_Export".

Then you can automate exporting this macro to the target database using VBA
during your build process, with something like:

DoCmd.TransferDatabase acExport, "Microsoft Access", strDbPath, acMacro,
"Autoexec_For_Export", "Autoexec", False

- Steve
 
6

'69 Camaro

Hi, Mark.

Sorry to bother you, but it appears that you tried to mark my post above as
an answer to your question, but Microsoft's Web portal is still buggy and it
didn't recognize you as the original poster of the question. Would you
please do me a favor and sign into the Microsoft Online Community with your
..Net passport again and answer "Yes" to the question "Did this post answer
your question?" for my post above? If it recognizes you as the original
poster, then a green check mark should appear on my post above if you wait
about a minute and then refresh the Web page.

Thanks! It's much appreciated!

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top