How to create a macro programmatically with Visual Basic?

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 --
 
B

Brian

You probably already solved your problem, but what about giving the macro a
different name, then DoCmd.CopyObject, and finally renaming the macro in the
live DB? That's just a guess, because I am assuming that the rename process
for the macro might be similar to the rename process for a table or field.
 

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