I have hundreds of VB I want to get rid of..Can I use
anything that will delete all code under the heading
general in one go or have I to delete them one at a
time ?
Richard,
You delete the modules behind the 300 forms by
setting each form's "HasModule" property to "False".
You can do this for all 300 forms using some vb code
as illustrated below. However...
As this is a very destructive procedure, you will definitely
want to make a backup copy of your database first!
As I thought you may have some forms that you don't
want to remove the modules from, you'll notice that, in
the following code, you can list the forms that need to
keep their modules on the line beginning "Case ...",
eg Case "Form1", "Form2", "Form3", etc.
Regards
Geoff
Sub DeleteFormCode()
' Assumes reference to "Microsoft DAO 3.6 Object Library"
' (set in vba editor on Tools References menu)
' Warning - backup the database first! This code will
' remove code behind all forms, except those listed as
' exceptions.
Dim db As DAO.Database
Dim cntForms As DAO.Container
Dim docFrm As DAO.Document
Dim strFormName As String
Dim frm As Form
On Error GoTo HandleErrors
Set db = CurrentDb()
Set cntForms = db.Containers("Forms")
For Each docFrm In cntForms.Documents
strFormName = docFrm.Name
Select Case strFormName
Case "Form1", "Form2", "Form3"
' List on the above line all the form names
' you DON'T want to remove modules from.
Case Else
' All other forms will have their modules
' removed by this code:
DoCmd.OpenForm strFormName, acDesign
Set frm = Forms(strFormName)
frm.HasModule = False
DoCmd.Close acForm, strFormName, acSaveYes
End Select
Next
Bye:
Set frm = Nothing
Set docFrm = Nothing
Set cntForms = Nothing
Set db = Nothing
Exit Sub
HandleErrors:
MsgBox Err.Description, vbOKOnly, "Error No: " & Err.Number
Resume Bye
End Sub