开发者

Getting at VBA/Access Source Code

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 开发者_如何学Ca 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?


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.


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


  • 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


  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜