Solved

Corrupted VBA

Posted on 2014-09-22
6
656 Views
Last Modified: 2014-09-23
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
0
Comment
Question by:pdvsa
6 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 40338321
You can try opening Access and DB with the /Decompile switch:

"C:\Program Files\MO2003\Office11\msaccess.exe" /decompile "C:\OPR_FE.MDB"

changing this to the correct path for MSAccess.exe and your DB.

That may or may not fix it.   Other options:

1. Recover everything from the DB except code on your own.  You can use the SaveAsText and LoadFromText methods to recover objects if you can't import them.
2. Use a backup (and I realize you said you didn't have a good one)
3. Use a professional recovery service. Maybe expensive and results can vary depending on the corruption

Jim.
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40338348
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"
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 40339250
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:pdvsa
ID: 40339607
that fixed it!  thank you.  

Looks like Jim responded a tab bit earlier.
0
 
LVL 57
ID: 40339659
Now don't forget those backups<g>

Jim.
0
 

Author Comment

by:pdvsa
ID: 40340029
I was lucky that it worked.  I just backed it up.  thanks for the reminder though.    thank you Pat for that.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question