Solved

Corrupted VBA

Posted on 2014-09-22
6
552 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
Comment Utility
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 26

Expert Comment

by:MacroShadow
Comment Utility
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 34

Expert Comment

by:PatHartman
Comment Utility
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Closing Comment

by:pdvsa
Comment Utility
that fixed it!  thank you.  

Looks like Jim responded a tab bit earlier.
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
Now don't forget those backups<g>

Jim.
0
 

Author Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now