UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> OutputModules    
CODE

' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' REV  DATE                          DESCRIPTION
' 1.0  2010-08-06              initial release
' 1.1  2010-09-12              revised function header
' 1.2  2012-01-30              added outputting of form and report modules
'
'==============================================================================
' NAME: OutputModulesToText
' PURPOSE: Outputs modules to text files
' RETURNS: Integer: number of files outputted
' ARGUMENTS: Optional Directory, CurrentProject.Path by default
'            Optional FileExtension, .bas by default
'==============================================================================
'ErrHandler V3.01

Public Function OutputModulesToText( _
  Optional OutputDir As String = "AppDirectory", _
  Optional FileExt As String = ".bas", _
  Optional IncludeFormsAndReports As Boolean = True) As Integer
On Error GoTo Error_Proc
Dim Ret As Integer
'=========================
 Dim i As Integer 'loop
 Dim iCount As Integer 'counter
 Dim db As Database
 Dim sObjectName As String 'form or report name
'=========================
 
 
  'init the arguments
  If OutputDir = "AppDirectory" Then OutputDir = CurrentProject.Path
  If Right(OutputDir, 1) <> "\" Then OutputDir = OutputDir & "\"
  If Left(FileExt, 1) <> "." Then FileExt = "." & FileExt
 
  Set db = CurrentDb()
 
  For i = 0 To db.Containers("Modules").Documents.Count - 1
    'change acOutputModule to acModule for Access 7.0 or earlier
    DoCmd.OutputTo acOutputModule, _
        db.Containers("Modules").Documents(i).NAME, _
        acFormatTXT, _
        OutputDir & db.Containers("Modules").Documents(i).NAME & FileExt
    iCount = iCount + 1
  Next i
 
 
 If IncludeFormsAndReports Then
 
   'forms
   For i = 0 To CurrentProject.AllForms.Count - 1
     sObjectName = CurrentProject.AllForms(i).NAME
     
     DoCmd.OpenForm sObjectName, acDesign
     DoEvents
     
     If Forms(sObjectName).HasModule Then
       DoCmd.OutputTo acOutputModule, "Form_" & sObjectName, acFormatTXT, OutputDir & "Form_" & sObjectName & FileExt
       DoEvents
       iCount = iCount + 1
     End If
     
     DoCmd.Close acForm, sObjectName, acSaveNo
     DoEvents
     
   Next i
 
   'reports
   For i = 0 To CurrentProject.AllReports.Count - 1
     sObjectName = CurrentProject.AllReports(i).NAME
     
     DoCmd.OpenReport sObjectName, acViewDesign
     DoEvents
     
     If Reports(sObjectName).HasModule Then
       DoCmd.OutputTo acOutputModule, "Report_" & sObjectName, acFormatTXT, OutputDir & "Report_" & sObjectName & FileExt
       DoEvents
       iCount = iCount + 1
     End If
     
     DoCmd.Close acReport, sObjectName, acSaveNo
     DoEvents
     
   Next i
   
 End If
 
 Ret = iCount
'=========================
Exit_Proc:
 OutputModulesToText = Ret
 Exit Function
Error_Proc:
 Select Case Err.Number
   Case Else
     MsgBox "Error: " & Trim(str(Err.Number)) & vbCrLf & _
       "Desc: " & Err.Description & vbCrLf & vbCrLf & _
       "Procedure: OutputModulesToText" _
       , vbCritical, "Error!"
 End Select
 Resume Exit_Proc
 Resume
End Function


Creative Commons License
OutputModules by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 4,118 times.  This page was last modified 16:52, 30 January 2012 by Jack Leach.   Disclaimers