Dan Waters
df.waters at comcast.net
Fri Oct 22 11:49:49 CDT 2010
To set this up, follow these steps: 1) Copy this public function into a standard module: Public Function AutoCompile () '-- Purpose: When this file is opened using a shortcut that has a /cmd AC in the target field, _ this function will run through. _ This mdb file has an AutoExec macro which calls this function. If Command() <> "AC" Then Exit Function DoCmd.RunCommand acCmdCompileAndSaveAllModules If Application.IsCompiled = False Then MsgBox "Your code could not compile." _ & vbNewLine & vbNewLine _ & "This must be resolved.", vbExclamation + vbOKOnly, "Code Not Compiled" Stop Else Application.Quit End If End Function Note: If you put this into its own standard module, then you can more easily distribute it into the access files you need to put it in. 2) Create a shortcut to the access file you want to Decompile+Compile. 3) Insert the full path to the Access executable into the beginning of the target field in the short cut properties. You'll need to surround that path with double quotes. 4) At the end of the target field enter the switches and argument '/decompile /cmd AC' without the single quotes. 5) In your .mdb, create an AutoExec macro. Enter the RunCode action, and enter AutoCompile() as the function name. If you already have an AutoExec macro, enter this as the first line. How this works: When you click on the shortcut, the file will first be decompiled. Then the AutoExec macro will run. The first line of the AutoExec macro will call the AutoCompile function. Because you set the value of cmd = "AC", the AutoCompile function will complete. The AutoCompile function will first CompileAndSaveAllModules. Then it will check to see if everything IsCompiled. If not, then you get a message and the code is stopped. If everything IsCompiled, then the .mdb file quits. If you click on a shortcut that does not include /cmd AC, then code execution steps out of the AutoCompile function, letting your file take the steps that it would otherwise normally do. Note: I tried adding a /compact to the target field, but then the file just compacted - it ignored /decompile and the AutoExec macro. HTH! Dan