Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modules to Text. Help. 1

Status
Not open for further replies.

thebernieb

Programmer
Jun 6, 2001
15
US
I'm looking for a way to send all modules to a text file. I can accomplish this pretty easily with documents container for stand-alone modules, but class modules are a different issue. Any suggestions?

Also, anyone know of any programs that format VB code from text files to MS Word or HTML with color and indents? I've been thinking of writing an MS Word module to do this, but really don't feel like spending the time. Let me know.

Thanks,
Bernie
 
I was just about to write something similar. I'm in the process of developing a form that will list the names of all my modules in a list box. What I want to do is select a name from the list and press a command button that will print the module code. I'm currently able to print the code in a .txt file by passing my function the name of the module (SEE CODE BELOW) but I cannot populate my list box with the names of the modules in my db.

I've searched through Access 2000 Developer's Handbook Volume 1: and have found in chapter 17 an example of what I'd like to do but I need to customize it and that's where I'm having difficulties. I can't figure out how to get just the Module info into a list box from their example. All I want is a list box listing all the module names of the current db and a command button to execute another function with the name selected in the list box. The example is in a tab format listing more info than I need, ie the table, query, form, report, ... etc names. Any suggestions and or code samples would greatly be appreciated.

Code to print out module
Code:
Sub PrintModuleOut(strModName As String)
    Dim strMsg As String
    
    On Error GoTo ErrHandler
    DoCmd.SelectObject acModule, strModName, True
    DoCmd.RunCommand acCmdOutputToText
    
SubExit:
    Exit Sub
ErrHandler:
    Select Case Err.Number
        Case 2544 'Probably an invalid name of module
            strMsg = strModName & " is not a valid module name."
            strMsg = strMsg & vbCrLf & "Please try again."
            MsgBox strMsg
            Resume SubExit
        Case Else
            strMsg = Err.Number & vbCrLf & Err.Description
            MsgBox strMsg
            Resume SubExit
    End Select
End Sub

I'm not sure if this is what you are already looking for but if it helps then great. Any chance you have an answer to my question???
 
HiBoo,

I think that code would work to print stand alone modules, which I can do, but I'm looking for something to print class modules. In answer to your question however, you can fill a list box using a function. I'll try to give you some direction from what I know.


You'll need to set up a module with two functions. One function will be used as to fill the list box and the other will be used to enumerate the fill list box function. Dump this code into a module:

Option Compare Database
Option Explicit

Public pubvarModuleList() As String
Public pubvarEntries

Function FillModuleList(fld As Control, id, row, col, code)

Dim retVal
Dim x As String

On Error GoTo ErrorHandler

retVal = Null
Select Case code
Case 0
pubvarEntries = 0
pubvarEntries = GetModuleNames(pubvarModuleList())
retVal = pubvarEntries
Case 1
retVal = Timer
Case 3
retVal = pubvarEntries
Case 4
retVal = 1
Case 5
retVal = -1
Case 6
retVal = pubvarModuleList(row)
Case 9
ReDim pubvarModuleList(0)
pubvarEntries = 0
End Select
FillModuleList = retVal

ErrorHandler:
Resume Next

End Function

Function GetModuleNames(names() As String)
Dim cntrModule As Container
Dim dbs As Database
Dim intArrayLength As Integer
Dim intVar As Integer


Set dbs = CurrentDb

intArrayLength = 0

Set cntrModule = dbs.Containers("Modules")
If cntrModule.Documents.Count <> 0 Then
intArrayLength = cntrModule.Documents.Count
ReDim pubvarModuleList(0 To cntrModule.Documents.Count - 1)
intVar = 0
For intVar = 0 To (intArrayLength) - 1
names(intVar) = cntrModule.Documents(intVar).Name
Next intVar
End If
GetModuleNames = intArrayLength

End Function

'-------

There's some text wrapping in this text box, but I'm sure you can figure out where everything goes.

Now in order for this to work, you have to select the listbox properties on the form you are working in. Then, set the listbox's RowSourceType to FillModuleList. If you use a command button to fill the list box, the code you would use in the command button click event to enumerate the list box is:

list0.requery

'----

list0 of course refers to the name of the listbox you want to display the module names in.

Hope that helps. Let me know.

Bernie

 
To thebernieb,

I tried out your code and it was successful!!! This is exactly what I was looking for! Thank you very much!

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top