How does one decompile and recompile a database application?
Asked Answered
P

6

40

I have an Access database application and I would like to know the proper way of decompiling and recompiling it.

Palermo answered 16/7, 2010 at 15:40 Comment(1)
In your previous question #3258988 you accepted an answer that includes information on decompiling and recompiling.Ectoparasite
C
14

The accepted answer is great, but it's a little impractical to create a shortcut for every database.

You can save this as a powershell module.

#for use with MSAccess 2010

Function Decompile-AccessDB{
    param ([string]$dbFileName)

    [string]$argument = '"' + $dbFileName + '"' + "/Decompile"
    Start-Process -FilePath 'C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE' -ArgumentList $argument
}

Then call it like this:

Decompile-AccessDB -Path "C:\Path\to\some.accdb"

This allows you to quickly and easily decompile any db from the power shell command line.

Note that you still need to hold down the Shift key when you run this to bypass the application startup.

Calabash answered 28/2, 2014 at 18:19 Comment(1)
Dynamically get the full path to the access executable this way: (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE").'(default)'Gustafson
S
55

To Decompile an Access database you'll need to create a shortcut with the following elements:

  1. Path to the MS Access Executable (MSACESS.exe)
  2. Path to the database you would like to decompile
  3. The /decompile flag

All together, then, the shortcut would look something like the following:

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\users\tim\documents\Mydatabase.mdb" /decompile

Obviously, the paths will be different on your system.

I'd recommend making a backup of your database before running this command.

If you have any startup code in your database you should hold down the shift key to bypass the startup code execution.

Once the database opens, you can compact and repair the database to ensure optimal performance.

After the compact and repair, you can recompile the VBA code by opening any module and using the Debug Compile [DatabaseName] command.

If this is something you want to do frequently, you can create an "Access Decompile" shortcut in your SendTo Menu. Once you have this shortcut in the SendTo Menu you'll be able to right-click on any Access database and select "Send To --> Access Decompile", which is much easier than having to create a shortcut to the specific database.

Follow these steps to customize the Send To menu with an Access Decompile shortcut

  1. Create a shortcut to the Access executable.

  2. Append the /decompile flag in the Target for the shortcut. The shortcut will look like this:

    "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /decompile

  3. Open Windows Explorer and paste the following into the address bar:

    %APPDATA%\Microsoft\Windows\SendTo

  4. Copy the shortcut you created into the SendTo Folder.

  5. The Access Decompile Shortcut will now be available for use.

To invoke the Access Decompile shortcut, right click on an Access Database in Windows Explorer and select "Send To --> Access Decompile". Be sure to hold the shift key down to bypass any startup code in the database.

Singles answered 16/7, 2010 at 16:11 Comment(1)
To find the path to MSACCESS.EXE, run this in a console: reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE" /veKyphosis
U
42

@Tim Lentine's practical instructions are good, but he leaves out the actual steps required for a decompile to be worth doing:

  1. backup your database.

  2. compact your database.

  3. using the shortcut created with Tim's instructions, open your database.

  4. close that instance of Access.

  5. open a new instance of Access and open the database you just decompiled, but BE SURE YOU BYPASS ALL STARTUP CODE (i.e., hold down the shift key). If you don't do that, then you might as well go back to step 3 and try again, since if the startup code runs, your code will recompile before you are ready to do so.

  6. compact the decompiled database (and be sure you hold down the shift key so that it bypasses the startup code; see #5).

  7. open the VBE and on the Debug menu, choose COMPILE [name of project].

  8. on the file menu, save the project.

  9. compact again.

Why are all these steps necessary?

Because you want to not just decompile the VBA, you want to make sure that all the data pages where the compiled p-code was stored are completely discarded before you recompile.

I also recommend:

  1. in VBE options, turn off COMPILE ON DEMAND

  2. in the VBE, add the COMPILE button to your toolbar.

  3. compile often with that button on the toolbar, after every two or three lines of code.

Decompile is not something you should use all the time, but during heavy-duty coding, I might do a decompile a couple of times a day. And I generally decompile/recompile as the last step before releasing an app into production use.

Last of all, read Michael Kaplan's article on the subject to understand it better.

Undercarriage answered 16/7, 2010 at 19:25 Comment(4)
This may sound like a daft question, but should I use decompilation even if the database is a data only database?Jewelljewelle
@Paul - It shouldn't be necessary because a data-only database will presumably not contain any VBA code. (BTW, you'll have to forgive David for not responding; he passed away several years ago.)Guiltless
@GordThompdon: Oh! No! That's definitely a fatal exception. Thanks for answering in his stead.Jewelljewelle
The parenthetical in step 6 seems to be the key. I've done all of these steps from multiple websites and shift-clicking when opening finally gave me an option to compile in the VBE.Insupportable
C
14

The accepted answer is great, but it's a little impractical to create a shortcut for every database.

You can save this as a powershell module.

#for use with MSAccess 2010

Function Decompile-AccessDB{
    param ([string]$dbFileName)

    [string]$argument = '"' + $dbFileName + '"' + "/Decompile"
    Start-Process -FilePath 'C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE' -ArgumentList $argument
}

Then call it like this:

Decompile-AccessDB -Path "C:\Path\to\some.accdb"

This allows you to quickly and easily decompile any db from the power shell command line.

Note that you still need to hold down the Shift key when you run this to bypass the application startup.

Calabash answered 28/2, 2014 at 18:19 Comment(1)
Dynamically get the full path to the access executable this way: (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MSACCESS.EXE").'(default)'Gustafson
M
7

The other answers here all seem a little complex to my taste.

To decompile an Access database:

Open the Run dialog from the start menu, or hit Win + R

Type in: MSACCESS.EXE /decompile (a proper installation should open up the Access application, you could also provide the full path to MSACCESS.EXE), and press OK.

Access now opens. Open up your DB in the Access window that just opened. That will decompile it.

Muddy answered 10/3, 2018 at 21:54 Comment(2)
This is a simple approach but I'd like some further clarification. Are you saying that opening MSACCESS.EXE with the /decompile switch, without passing a filename, and then opening a database file from that instance will force a decompile on that database? Does this also mean that any other database I open from that instance of Access will also decompile when it opens? I'm not used to opening database files this way. I had always thought that the /decompile switch was applying to the file being opened, not the Access instance being opened. How can we know for sure?Armlet
@Armlet One way is just to use it and check. I've extensively used this technique when one of my databases when debugging a bug causing VB project corruption and hard crashes on startup, requiring decompilation often. But you can easily verify how it works by first compiling multiple databases, then open an Access instance using the decompile flag, and then see if you can compile them again (if they're compiled and nothing changed, that shouldn't be possible). You'll see that only the first database opened will get decompiled.Muddy
F
6

I wrote a VBS script to automate the process of decompiling. It's silly that Microsoft hasn't integrated this into Access, considering it is a necessity when developing VBA-heavy applications.

The script locates MSACCESS.exe and runs Access with the decompile flag on a database located in the parent directory of the script, whose name is given in the code.

Option Explicit
Dim MSAccPath
Dim RegKey
Dim WSHShell
Dim currentDirectory

' Get MSACCESS.exe directory
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
    & "CurrentVersion\App Paths\MSACCESS.EXE\Path"
Set WSHShell = WScript.CreateObject("WScript.Shell")

' Get parent directory
MSAccPath = WSHShell.RegRead(RegKey)
currentDirectory = WSHShell.CurrentDirectory

' Decompile
WSHShell.Run Chr(34) & MSAccPath & "MSACCESS.EXE" & Chr(34) & " " & Chr(34) & currentDirectory & "\..\testdb.accdb" & Chr(34) & " /decompile"

' Clear shell var
Set WSHShell = Nothing

Simply paste this text into a document with a .vbs extension and double-click it to run. Access will launch, decompile the compiled P-code ("packed" code), and automatically recompile the VBA source back into P-code.

Feltner answered 18/12, 2013 at 19:3 Comment(0)
G
1

Or simply you can create a shortcut on your Desktop (with the /Decompile Flag) and drag drop your Access application holding SHIFT to bypass any code

Gangplank answered 24/4, 2019 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.