Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Export module to text file using VBA (Access 97)

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 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