Solved

Export module to text file using VBA (Access 97)

Posted on 2004-08-17
3
1,352 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 119

Accepted Solution

by:
Rey Obrero 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now