Solved

Export module to text file using VBA (Access 97)

Posted on 2004-08-17
3
1,366 Views
Last Modified: 2012-02-08
I guess everything is in the title.

I need a simple VBA code that would export a given module to a text file.

Any ideas?
0
Comment
Question by:ornicar
3 Comments
 
LVL 4

Expert Comment

by:Colonel32
ID: 11821588
Add a project reference to the 'Microsoft Visual Basic for Applications Extensibility Library' (VBE menu, 'Tools/References'); this code should do the trick:

Public Sub VBE_ExportModule()
Dim modComp As VBComponent

'change this constant to your desired output folder path
Const EXPORT_FILEPATH As String = "C:\"

    For Each modComp In Application.VBE.VBProjects(1).VBComponents
        If modComp.Type = vbext_ct_StdModule Then
            modComp.Export EXPORT_FILEPATH & modComp.Name & ".bas"
        End If
    Next modComp

End Sub
0
 
LVL 44

Expert Comment

by:GRayL
ID: 11821648
Try reading VB Editor Help - Answer Wizard - Outputto method. There is a good explanation of the function plus examples.

Of course you already know about rightclicking on the module name in the Project Explorer and selecting Export Module.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 11823211
try this


Private Sub ExpModule_Click()
Dim strModuleName As Variant, strLoc As Variant
    strModuleName = InputBox("Enter Module Name")

ExportModule (strModuleName)
End Sub


Function ExportModule(strModuleName As String)

Dim DB As DAO.Database
Dim i As Integer
Dim strMyExt As String
Dim strNewLoc As String, strMyLoc As Variant
strMyLoc = "C:"
Set DB = CurrentDb()
strMyExt = ".txt"  ' Set extension for file names.
' Loop through module names.
For i = 0 To DB.Containers("Modules").Documents.Count - 1
   If DB.Containers("Modules").Documents(i).Name = strModuleName Then
   strNewLoc = strMyLoc & "\" & strModuleName & strMyExt
   DoCmd.OutputTo acOutputModule, strModuleName, acFormatTXT, _
      strNewLoc, 0
    End If

Next i


End Function
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question