INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How To

DB corrupt, get rid of error by MakeItSo
Posted: 8 Jan 04 (Edited 14 Jun 07)

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.

If not, then for each form you must: (Code follows below list)
  • Open in code view
  • Copy/Paste code to a text file
  • Set 'HasModule' property to 'No', this will erase all code!
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!!

CODE


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


    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

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: Microsoft: Access Modules (VBA Coding) and other Access fora.

MakeItSO

Back to Microsoft: Access Modules (VBA Coding) FAQ Index
Back to Microsoft: Access Modules (VBA Coding) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close