Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DB corrupt, get rid of error

How To

DB corrupt, get rid of error

by  MakeItSo  Posted    (Edited  )
Applies to at least Access 97 and 2000.

See also Knowledge Base Article - 304548:
http://support.microsoft.com/default.aspx?scid=kb;en-us;304548&Product=acc2000

If you import any form(s) containing vb-code into another database, the result can be db corruption.
You will get error messages like 'The event 'OnClick' has caused errors' or 'Unable to save - Network connection may have been lost' or similar.

Sometimes a simple 'Compact and repair' will suffice.

Another option is to decompile the database.
Refer to http://www.granite.ab.ca/access/decompile.htm

Great thanks to RoyVidar for this hint. [img http://home.arcor.de/andygalambos/6.gif]

If not, then for each form you must: (Code follows below list)
[ul]
[li]Open in code view[/li]
[li]Copy/Paste code to a text file[/li]
[li]Set 'HasModule' property to 'No', this will erase all code![/li][/ul]

Having done this, you can import your forms to a new db, paste the code from the text file(s) back to the respective form and set the 'HasModule' property to 'Yes'

Here's some code that will save all modules to text files, credits to DeanWilliams!! [img http://home.arcor.de/andygalambos/13.gif]
Code:
[blue]
Public Function SaveCodeModules()
    
    Dim dbs As DAO.Database
    Dim strCode As String
    Dim vbComp
    Dim a
    Dim fs
     
    Set dbs = CurrentDb
    
    For Each vbComp In vbe.VBProjects(1).VBComponents
        With vbComp
            strCode = .CodeModule.Lines(1, .CodeModule.CountOfLines)
            Set fs = CreateObject("Scripting.FileSystemObject")
            Set a = fs.CreateTextFile("C:\Code\" & .Name & ".txt")
            a.Write strCode
            a.Close
        End With
    Next vbComp[/blue]
[red]
    Dim frm As Form
    Dim rpt As Report
    Dim obj As AccessObject
    
    For Each obj In CurrentProject.AllForms
        DoCmd.OpenForm obj.Name, acDesign
        Set frm = Forms(obj.Name)
        frm.HasModule = False
        DoCmd.Close acForm, frm.Name, acSaveYes
    Next
    
    For Each obj In CurrentProject.AllReports
        DoCmd.OpenReport obj.Name, acDesign
        Set rpt = Reports(obj.Name)
        rpt.HasModule = False
        DoCmd.Close acReport, rpt.Name, acSaveYes
    Next
[/red]
End Function

Add the code in red if you want to set the HasModule property of your forms and reports set to No.

Credits to DeanWilliams for the code snippet, one of the VIP participants of forum705 and other Access fora.

MakeItSO
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top