Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

ms access - How to skip Autoexec macro when opening MSAccess from MSAccess?

So I have an MSAccess MDB that needs to open other MDB's and run a bunch of code that will compare two Access MDB's to find code differences,query diffs,etc. The goal being to verify any production MDB has not been altered from the original deployment.

My problem is that many of these Access apps have Autoexec macros and there is no simple way to call .OpenCurrentDatabase without running the autoexec macro.

How can I just skip the macro using CODE?

I know I can hold down the shift key. I know I can turn that option on and off too.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's a sneaky solution but it works for me.

I do a DoCmd.DatabaseTransfer acImport of the Autoexec macro. Then I replace the autoexec with a blank one, using DoCmd.DatabaseTransfer acExport

The trick is that an Export will overwrite

DoCmd.TransferDatabase acImport, "Microsoft Access", sSourcePath, acMacro, "autoexec", "autoexecSource"

DoCmd.TransferDatabase acExport, "Microsoft Access", sSourcePath, acMacro, "autoexecblank", "autoexec"

I do that again for the second MDB

DoCmd.TransferDatabase acImport, "Microsoft Access", sDestPath, acMacro, "autoexec", "autoexecDest"

DoCmd.TransferDatabase acExport, "Microsoft Access", sDestPath, acMacro, "autoexecblank", "autoexec"

Then I can do all the comparisons for finding Diffs between the two MDBs without triggering the autoexec macros since I imported them and replaced them

Then I compare the two Macros I imported and then export them back to the databases.

DoCmd.TransferDatabase acExport, "Microsoft Access", sSourcePath, acMacro, "autoexecSource", "autoexec"

DoCmd.TransferDatabase acExport, "Microsoft Access", sDestPath, acMacro, "autoexecDest", "autoexec"

Obviously this solution only works using VBA in Access, but it does work.

Hope this helps someone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...