Solved

Export module to text file using VBA (Access 97)

Posted on 2004-08-17
3
1,369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

756 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