Solved

Corrupted VBA

Posted on 2014-09-22
6
608 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 35

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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