How to create a macro programmatically with Visual Basic?

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

How would one write VB code (in a stand-alone app) to create a new
macro in an Access dB?

I know you all will ask why would I want to do that, so here are my
reasons...

My VB app is currently in production and there are hundreds of copies
in customers' hands. It ships with and uses 3 Access databases.
Several customers have complained that their employees can open the
databases using MSAccess. They want to prevent this.

One method is to add an AutoExec macro in the databases with a single
action: "Quit." I can also disable the Shift bypass key.

This is fine for all new shipments of my databases to new customers.
However, existing customers need to update their databases to add this
macro. My boss says we can't ask a customer to manually add this macro
themselves - I need to write an "update" program that will do it
automatically for them.

I can easily write a VB program to set the "AllowBypassKey" property to
"True," but how would this same program add the AutoExec macro to the
existing database?

I thought about providing a plain empty database with nothing in it
except for the macro, then using DoCmd.CopyObject or
DoCmd.TransferDatabase, but both of these require opening the source
database as an Access Application - but when it opens, the AutoExec
macro in it closes it! (DUH!)

If there's no way to create/copy/import a new macro, does anyone have
any other ideas?

-- I also posted this to microsoft.public.access.macros --
 
Rather than create a macro...set AllowBypass = False and all the startup
properties to false. They'll be able to open it, but they won't be able to
do anything.

However, setting the properties indicated or creating an AutoExec macro will
not resolve the problem you are trying to address entirely. All one would
need to do to get around these measures is link to your database from
another database. If you really need to prevent access to the data, you
need to implement user level security.
 
I had hoped the users wouldn't be sophisticated enough to know how to
link them, but ... some may ...

The AutoExec - Quit solution is so simple - and it works. But you're
right, from what little I know about user level security, it would be
better. Considering how involved it can get, I hoped to avoid it, but
I guess it's time to roll up my sleeves and dig in...
 
Pardon my ignorance but how does one disable the Shift bypass key? I have
pored over the MS Access Help page and have tried to write a macro and also
to use the Code Builder method. The name of the form that my database opens
to is SWITCHBOARD and i want to prevent users from bypassing my startup
properties.

Thanks,
Mimf
 

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

Back
Top