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.
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!!
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
Add the code in red if you want to set the HasModule property of your forms and reports set to No.