Solved Visual Basic Is CORRUPT!

khodor

Member
Local time
Today, 15:23
Joined
Feb 2, 2021
Messages
39
Hi everybody
After I created an Access file and worked on it for a while, My Laptop became so slow, so I decided to add SSD hard disk to make it faster, and I Formatted the C Hard Disk, then I re-downloaded the Access program but when I accessed my access file gives me this message:
the visual basic for applications propject in the database is corrupt
What Shell I Do?
 
1. Does the file open at all?
2. Can you import the objects into a new database?

It sounds like it might be too late but try a decompile and recompile (if possible at this point).
 
If you can open the db but not run a form or report, you can save and load from text as the last attempt.
 
Hi Thanks for your reply
1) Yes It open the databases, forms and tables but they are not working
for example I have a login page when you open the document, the form appears but when you press submit nothing happens
2) No I can't import it, The same message appears.
I tried these steps but nothing is working
I Can't enter vba
 
Last edited:
Did you try the decompile? I am not hopeful, but you have to try that first.
 
No Backup then?
Can you create a test DB and try and import from bad DB?
 
If you can open the DB and actually see the code in the module (just can't run it) then you could TRY to export the VBA code to a TEXT file. That would perhaps help.

If you have another DB of any other Access subject, can you open and run that? (Trying to eliminate possibilities here...)
Can you try to do a re-install of Office with the Repair option? That sometimes helps.

Make a copy of the DB (use the file explorer and do a copy/paste... just in case it goes funky on you) and try to Compact & Repair on it. NEVER do that to the last & only copy of the DB.
 
A wild guess here, is it possible that there is a reference missing in the visual Basic ?
1631112006506.png

I had problems with excel VBA once and it is a pain to fix.
 
it's not a simple reference issue. the VBA is corrupt, so it is not viewable.
 
it's not a simple reference issue. the VBA is corrupt, so it is not viewable.
In some cases, this can prevent you from opening the VBA editor. To fix it, I had to find an old office install with the correct reference and remove the bad one.
In any case, I hope he can still retrieve his code...
 
I have also been able to open a db with this error with a different version of Access. Without a backup though, you are pretty much SOL unless you want to pay a recovery service to try to get back the code for you. I think Jon, the owner of this Forum might do recovery. PM him to ask.

Here ia a work in progress. Currently the db opens a hidden form first which then opens the switchboard. When the initial form closes (first opened, last closed is how Access works), it checks to see if any changes were made since the last back up and if changes were made, it asks if you want to back up. This is a painless way to force yourself to make many backups as you are developing. See if you want to incorporate the form and log table into your apps going forward.

I am currently working on expanding the options which is why it is a work in progress so that it will also use the export to text method as a back up and then recreate from the exported objects. Since with the FE, we don't care about data, the Export to Text is actually a better option since the text exports don't get corrupted. If you have corruption in the db, sometimes you have to go back several versions to find a copy without that corruption.
 

Attachments

Last edited:
I may be able to recover your application depending on how badly corrupted it is.
However doing that would be chargeable in terms of the time required.
If interested, either send me a PM or email me
 
Hi everybody
Good News
I sent the access file to another laptop and it worked well
I tried to repair access but the same problem occurs
now I Have to focus on the difference between the two laptops:D:D
Thanks For Your help
 
do not mixed edit your db on x64 and x32 msa.
 
If it works correctly on another system, that points an accusing finger at the machine you WERE using originally when you reported the problem. There are TWO places to consider as prime candidates for the "offending" machine.

1. Reinstall Office with the Repair option. The Office files are, of course, installed to the local drive and thus part of "machine-specific" stuff.

2. References are affected by the registry, which is also unique to each machine. Compare the references on the working machine vs. failing machine. Remember that the references can be moved up or down in reference order - by highlighting a reference and then using the up and down arrows to the right. Make the references match, not only in what is checked but the order in which they appear.

IF you can export your VBA code to text files using that other system, you can easily import the files later in case your code needs a total restoration. Remember to export both class modules and general modules. Access will want to do those exports one module at a time.

Arnel's comment about 32-bit vs. 64-bit is also appropriate.
 
One thing you can do is export all the objects to text. Then create a new, empty FE. Link all the necesary tables. Import all the objects. Reset all the database properties. This should get rid of the corruption.

The second block of code is to import the items. I generally do it one at a time but in this case, you can use the same logic as the export code. Just change the SaveAsText to LoadFromText and use the correct object type
Code:
Public Sub RunCode()
    Call ExportDatabaseObjects("Modules")
    Call ExportDatabaseObjects("Forms")
    Call ExportDatabaseObjects("Reports")
    Call ExportDatabaseObjects("Querydefs")
    Call ExportDatabaseObjects("Scripts")
End Sub

Public Sub ExportDatabaseObjects(ExportType As String)
On Error GoTo Err_ExportDatabaseObjects
    
    'Dim db As Database
    Dim db As DAO.Database
    Dim td As DAO.TableDef
    Dim D As Document
    Dim C As Container
    Dim i As Integer
    Dim sExportLocation As String
    
    Set db = CurrentDb()
''import from text =
''application.Application.LoadFromText acForm, "frmRisks","C:\Temp\TextRiskReview070615\Form_frmRisks.txt"


    sExportLocation = "F:\Data\___db backups - please do not remove\TextObjects\" 'Do not forget the closing back slash! ie: C:\Temp\
    
    Select Case ExportType
        Case "TableDefs"
            For Each td In db.TableDefs 'Tables
                If Left(td.Name, 4) <> "MSys" Then
                    DoCmd.TransferText acExportDelim, , td.Name, sExportLocation & "Table_" & td.Name & ".txt", True
                End If
            Next td
        Case "Forms"
            Set C = db.Containers("Forms")
            For Each D In C.Documents
                Application.SaveAsText acForm, D.Name, sExportLocation & "Form_" & D.Name & ".txt"
            Next D
        Case "Reports"
            Set C = db.Containers("Reports")
            For Each D In C.Documents
                Application.SaveAsText acReport, D.Name, sExportLocation & "Report_" & D.Name & ".txt"
            Next D
        Case "Scripts"
            Set C = db.Containers("Scripts")
            For Each D In C.Documents
                Application.SaveAsText acMacro, D.Name, sExportLocation & "Macro_" & D.Name & ".txt"
            Next D
        Case "Modules"
            Set C = db.Containers("Modules")
            For Each D In C.Documents
                Application.SaveAsText acModule, D.Name, sExportLocation & "Module_" & D.Name & ".txt"
            Next D
        Case "QueryDefs"
            For i = 0 To db.QueryDefs.Count - 1
                Application.SaveAsText acQuery, db.QueryDefs(i).Name, sExportLocation & "Query_" & db.QueryDefs(i).Name & ".txt"
            Next i
        Case Else
    End Select

    Set db = Nothing
    Set C = Nothing
    
    MsgBox "All database objects have been exported as a text file to " & sExportLocation, vbInformation
    
Exit_ExportDatabaseObjects:
    Exit Sub
    
Err_ExportDatabaseObjects:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_ExportDatabaseObjects
    
End Sub

Code:
Public Sub ImportModule()
Dim strPath As String
    strPath = "C:\Data\Work\SafetyMarking\Module_"
    Application.Application.LoadFromText acModule, "frmFillReport", strPath & "frmFillReport" & ".txt"
End Sub
 

Users who are viewing this thread

Back
Top Bottom