3

I'm rewriting a legacy access / VBA application in C#. While I am limited as a VBA programmer I am under the impression that the code is minimally compiled and runs almost as a script ? Obviously no security / VBA you can just hit alt + f11 to get at the source code is there a good way to decompile / get at this code?

So I tried this: http://forums.databasejournal.com/showthread.php?t=34222

which appears to be about how to decompile .mdb files.

However the program quickly recompiled itself - or at least says it is recompiling itself in the lower left status bar. Any ideas?

9
  • Not sure what you mean - You can use Alt + F11 to view the source. What do you need to decompile if you can view the plain-text source? Commented Jul 20, 2011 at 0:31
  • is it an .mde or a .mdb? Commented Jul 20, 2011 at 0:59
  • @bryan that my whole point usually I do just hit alt + f11 but there seems to be some kind of security on the .mdb file Commented Jul 20, 2011 at 1:46
  • I use SourceTools.xla (codeproject.com/KB/office/SourceTools.aspx) to extract all the code and forms from a Excel VBA project, so I can enter it into source control. Maybe this tools can be adapted for Access and it will help you in re-coding into C#. Commented Jul 20, 2011 at 3:42
  • There is no such thing (to my knowledge) as "decompiling an MDB file". Another option is to create a new Access database and import the code modules from the other DB. Your question is still very unclear as to what exactly you have and are trying to do. Commented Jul 20, 2011 at 14:36

4 Answers 4

7

Here are some suggestions (some of which I'm repeating from comments I've made above):

  • Alt-F11 is not my usual method of opening the VBE, because I usually want to go to the Immediate Windows. Try Ctrl-G, instead.

  • If both Alt-F11 and Ctrl-G fail to open the VBE, then perhaps the AllowBypassKey property of the database has been changed to False. To get code to change this, search the Access help file for AllowBypassKey (in the VBE, from the help menu, search for "AllowBypassKey"). However, you won't be able to run the code within the database you're trying to investigate if AllowBypassKey is turned OFF, so you can run this code:

//

  On Error GoTo Change_Err
    Dim db As DAO.Database
    Dim prp As Variant
    Const conPropNotFoundError = 3270

    Set db = DBEngine.OpenDatabase("C:\Databases\MyDatabase.mdb")
    db.Properties("AllowBypassProperty") = True

  exitRoutine:
    If Not (db Is Nothing) Then
       db.Close
       Set db = Nothing
    End If
    Exit Sub

  errHandler:
    If Err = conPropNotFoundError Then    ' Property not found.
       ' do nothing and exit
       Resume exitRoutine
    End If

Then you should be able to open the database when holding down the SHIFT key (which bypasses any defined startup routines, which might have been shutting off access to the VBE).

  • If the file is an MDE, there is no source code. You can find out if it's an MDE by checking this property:

    ?CurrentDB.Properties("MDE")

If it's an MDE (the file can have any extension), this will return "T". If it's not an MDE, it will throw an error (because the property doesn't exist).

  • Other things to check might be how many modules there are. If you have the database open and can get to the Immediate Windows (Ctrl-G), then this will tell you if there are any modules:

//

  ?CurrentProject.AllModules.Count
  • You also might be able to see what's in the database by opening up the Object Browser in the VBE (F2) and selecting the project name in the dropdown at the top (it will say "" by default

  • Last of all, you may think that it could be protected by Jet ULS, but starting with Access 2000, that's not a big possible, as there's nothing but a password on the VBA project available (i.e., it's no longer covered under Jet ULS). I would expect that if it were password-protected, you'd be prompted for the password somewhere along the line, so you'd already know that.

Sign up to request clarification or add additional context in comments.

Comments

3

If it's an .mde you are out of luck. You need to get hold of the .mdb containing the source VBA code that was compiled to create the .mde

5 Comments

The starting point is an .mdb file, I just looked. But theres some .dll in there as well bit of a shit show ?? Does that mean its accessible ?
An .mdb with no security is accessible, but it's starting to sound like you have a lot of business logic in compiled .DLLs
If alt+f11 doesn't work in the .mdb file is there a way to force it ?
Also there are no .dll in the local directory just on the server which makes me think that the client side business logic is entirely in vb6.
Try holding down the shift key when you open the DB if the DB objects window isn't showing up. That might get you a little further.
1
  • HOW TO VIEW SOURCE CODE (.mdb FILE)
    1. Select the file
    2. Hold the 'shift' key
    3. Then double click the file without releasing the 'shift' key

Comments

0
  1. Navigate to the Program Folders on your computer.

  2. Open the MS Office Folder

  3. Navigate to MSAccess.exe and make a shortcut of it.

  4. Move the shortcut to where your database resides (makes life easier and you'll need to do this for each database to decompile).

  5. (optional) Rename the shortcut to something like "decompiler for my database whose name is...." so you know that opening it blows away your compiled code

  6. Right-click on the shortcut to view its properties. In the Target field of the properties dialog box for the shortcut you'll see something like "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"

  7. In the target field, right-arrow to the end of the pathname, type a space, and then, in quotes, type (or paste) the full pathname of the location of your MS Access file to decompile (easiest way is to copy from the address bar on your window where the file resides, if you have the address bar showing).

  8. Still in the Target field, type a space, and then with no quotes, type /decompile

  9. Click OK to accept the changes and to close the dialog box.

  10. Hold the Shift key down and keep it down.

  11. Wiggle your ears

  12. Double-click on the shortcut.

  13. Go to any module in your database.

1 Comment

Decompiling the VBA doesn't do anything at all to make the canonical VBA code more accessible. If the database is secured or the AllowBypassKey is set, or if it's an MDE, the VBA code won't be accessible. Decompiling has ZERO effect on any of those issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.