Link to home
Start Free TrialLog in
Avatar of pdvsa
pdvsaFlag for United States of America

asked on

Corrupted VBA

Hello, I imported a form from a corrupted database.  I believe this is the source of my corruption.  I can now no longer view the code contained in any form as the db crashes each time I try to do this.  I have tried to make a new db and import the forms but it wont import.  

If the VBA project is corrupted then how can you fix it?  Or you can not fix it?  I cant believe that you would basically have to throw away the db and start all over. I dont have a good backup.  At least I am early in db creation so having to start over is not that bad.   I have been working on this for hours and I give up.  

thank you
Untitled.jpg
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There are two things you can try, if they don't help I guess you're out of luck.

1. Decompile and recompile the database. Follow the following steps:
    a. Create a new shortcut to the Access executable
    b. Add the path to your db
    c. Add the /decompile flag to the end of the shortcut
        The final path should look some thing like this (including the double quotes and spaces):
        "C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE"  "C:\Users\MacroShadow\Documents\Corrupt db.accdb" /decompile
    d. Launch the shortcut
    e. Close that instance of Access
    f. Open your db (not with the decompile shortcut) while holding down the shift button as to bypass any startup code
    g. Compact the decompiled database while holding down the shift button as to bypass any startup code
    h. Open the VBE, on the Debug menu, click COMPILE
    i. Save the project
    j. Repeat step g

2. Recover module source code. Follow these steps:
    a. Run this line of code to recover the code:
        Application.SaveAsText acModule, "ModuleName", "C:\PathToSaveRecoveredModule\ModuleName.txt"
    b. Create a new db
    c. Run this code to load the recovered module in the new db.
       Application.LoadFromText acModule, "ModuleName", "C:\PathToSaveRecoveredModule\ModuleName.txt"
You don't say what version of Access you are using.  In addition to the other suggestions I have occasionally succeeded in opening a corrupted database by using a different version of Access.  So, if you are using A2013, try opening the app with A2010 or A2007.  If it is an .mdb, you have a lot more choices.  I can't tell you why this worked for me, but it did.  In fact, I had one database that was such a nightmare that I ended up adding code in my login form so that whenever I closed the database (my ID personally, I didn't want this happening for the users), I had code that exported all the forms, reports, queries, modules to text so that if I opened the database the next time and it was corrupted (happened about 60% of the time), I could rebuild it.  Now I add this code to all my databases because it gives me some measure of source code control.
Avatar of pdvsa

ASKER

that fixed it!  thank you.  

Looks like Jim responded a tab bit earlier.
Now don't forget those backups<g>

Jim.
Avatar of pdvsa

ASKER

I was lucky that it worked.  I just backed it up.  thanks for the reminder though.    thank you Pat for that.