3

This morning, I got this error

Error accessing file. Network connection may be lost

no matter what I was doing on any form. So I opened a blank database and imported everything. Some error occurred but it said that the import was successful. I was able to open my form again. Then I went back the old copy and then I got this error when I try to open the database

The database cannot be opened because the VBA project contained in it cannot be read

Even the backup I did before the first error is saying that now.

and I tried to import again and I got the error while it was importing.

I'm getting abit nervous now, plz tell me there's a way to fix this

thank you

Marc
  • 16,170
  • 20
  • 76
  • 119
  • 1
    Try decompile on a copy of your db file: http://stackoverflow.com/questions/3266542/ms-access-how-to-decompile-and-recompile – HansUp Oct 09 '12 at 16:32
  • 2
    Make sure you make and keep good backups. My development databases occasionally (although rarely) become so corrupted that I cannot recover them no matter what I do. – HK1 Oct 09 '12 at 16:44
  • @HansUp when it decompiles, I got the same error – Marc Oct 09 '12 at 17:06
  • Which error now? (You mentioned 2 different errors.) If it's the first error, do you get that error message immediately every time you open the db? Or is it only afterward ... when you open any form? – HansUp Oct 09 '12 at 17:08
  • Sorry, it's the second one. Immediately when the db opens – Marc Oct 09 '12 at 17:12
  • If Access still complains the VBA is corrupt, that means decompile wasn't able to fix the problem. The simplest fix is to restore from your last good backup. – HansUp Oct 09 '12 at 17:17
  • Thank you sir. Can you write this as an answer so you can have your points. BTW, do you know why access get corrupted? I just added 2 lines of code and I got that. – Marc Oct 09 '12 at 17:31
  • 3
    Compiled VBA code can get corrupted during periods of active development for reasons I don't understand. That's why decompile is recommended as a regular practice during development. Perhaps the compiled VBA could also become corrupted later (after development, during production use of the application) ... but I don't think I've ever seen that happen since I started developing with Access in 2005. – HansUp Oct 09 '12 at 17:33
  • Thank you, I will be glad to accept this as an answer. – Marc Oct 09 '12 at 17:36

2 Answers2

5

You can try decompile when Access complains it can't read the VBA project code. See the two answers to this SO question for detailed instructions: HOW TO decompile and recompile.

If decompile is unable to restore your application to good working order, the quickest solution is probably to revert to your last good backup copy.

If you're willing to put in extra effort to recover module changes since the last backup, check whether you can still access the module source code. If the source code is readable, you can use the undocumented SaveAsText method to dump the code to a text file:

Application.SaveAsText acModule, "Module1", "C:\SomeFolder\Module1.txt"

Then later load it into a new db file with the LoadFromText method.

Application.LoadFromText acModule, "Module1", "C:\SomeFolder\Module1.txt"
Community
  • 1
  • 1
HansUp
  • 95,961
  • 11
  • 77
  • 135
  • Trying my luck at an old thread... I tried this in the immediate window in Access 2007 but get a Run-time error: '3021' No current record. I have a form which contains the code which I want to retrieve. Here is what I used: Application.SaveAsText acForm, "App_Form", "C:\Users\jck112\Module1.txt" – user793468 May 30 '13 at 22:20
  • 1
    I get the "Unexpected error (40230)" when trying to open the vba. I tried decompiling, which is how I found the project is corrupt. Is there anyway I can retrieve my code? – user793468 May 30 '13 at 22:23
  • Since `SaveAsText` didn't work, you may be out of luck. You could try importing the form into another db file, if you haven't already. However my best guess is that will also fail in this case. Still try it in case I guessed wrong. Your only recourse may be to restore the form from the last backup. – HansUp May 30 '13 at 22:38
  • I tried importing the form, but it didnt allow me to. It allows me to import tables, queries from the same DB but it wont let me select the form, it is disabled. – user793468 May 30 '13 at 22:41
  • What is the file extension of your db file? Some possibilities are: mdb; mde; accdb; accde; accdr; adp; ade. – HansUp May 30 '13 at 22:43
  • I have both .accdb and .accde files, anyway to retrieve code from .accde?? – user793468 May 30 '13 at 22:45
  • The accde version does not include source code, only compiled code. But it you can't retrieve the source code from the accdb version, I don't know any other way except to try a commercial service --- some claim to be able to recreate usable source code from a compiled db file. However I've not tried one of those. – HansUp May 30 '13 at 22:47
  • The form functions perfectly fine when used. Button clicks do as expected, so the code behind these buttons work. But I need to make some enhancements to the code. – user793468 May 30 '13 at 22:47
  • I updated my last comment. I'm afraid I can't offer anything more. Sorry. – HansUp May 30 '13 at 22:50
  • Thanks for the info. Let me know if you come across any article which demonstrates recreating usable source code from a compiled db file. – user793468 May 30 '13 at 22:52
0

For those still having this issue, here's an update. This issue occurs when the .accde is compiled on a version of Access that is newer than that of the affected computer. It turns out that some machines were being updated with windows update and some weren't. After getting all installations of Office to the same version number by installing SP2 and then a February, 2016 update, the executable now runs on all my machines.

Here's the Link to SP2 (make sure you download the correct file.) https://www.microsoft.com/en-us/download/details.aspx?id=39667

Here the February, 2016 update: https://support.microsoft.com/en-us/kb/3114750

HTH, Patrick