Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Export module to text file using VBA (Access 97)

Posted on 2004-08-17
3
Medium Priority
?
1,413 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 2000 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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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