Compile A Database
acCmdCompileAndSaveAllModules, acCmdViewCode
This example will Compile and Save all modules. The code was kindly provided by Dev Ashish.
'***************** Code Start *******************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
Function fCompileProject() As Boolean
Dim db As Database
Dim ctr As Container
If Not Application.IsCompiled Then
Set db = CurrentDb
Set ctr = db.Containers!Modules
If ctr.Documents.Count > 0 Then
DoCmd.OpenModule ctr.Documents(0).Name
DoCmd.RunCommand acCmdCompileAndSaveAllModules
DoCmd.Close acModule, ctr.Documents(0).Name
Else
'No Modules present, try Forms container
Set ctr = db.Containers!Forms
'no need to check for count since this code itself must be present *somewhere*
With ctr.Documents(0)
DoCmd.OpenForm .Name, acDesign
DoCmd.RunCommand acCmdViewCode
DoCmd.RunCommand acCmdCompileAndSaveAllModules
DoCmd.Close acForm, .Name
End With
End If
End If
fCompileProject = Application.IsCompiled
End Function
'****************** Code End ********************