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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to do the same thing the object browser does, or use it! 1

Status
Not open for further replies.

MikeDNova

Programmer
Jul 3, 2002
86
0
0
US
Hey guys,

I'm trying to get a list of all the functions in my projects (added references) and ones already in access. And then maybe list them in a form or something. I'm having trouble finding a way to mimic the functionality of the object browser which lists all the available functions by module.

Any suggestions?

Thanks,
Mike
 
This is a non-trivial topic, hence the dearth of replies. Bumping probably isn't a good idea; it gives the idea that an answer has been generated.

0) Create a form with a tree control (active x)

1) Create a module with this code:

[tt]
Option Compare Database
Option Explicit

Sub AddSub(TheLine As String, MyTreeView As Object, ParentNode)
Dim SpacePos As Integer
SpacePos = InStr(TheLine, " ")
Dim ParenPos As Integer
ParenPos = InStr(TheLine, "(")
If SpacePos <> 0 And ParenPos <> 0 Then
Dim FunctionName As String
FunctionName = Mid(TheLine, SpacePos + 1, ParenPos - SpacePos - 1)
MyTreeView.Nodes.Add ParentNode, tvwChild, FunctionName, FunctionName
Debug.Print &quot; [&quot; & Mid(TheLine, SpacePos + 1, ParenPos - SpacePos - 1) & &quot;]&quot;
End If
End Sub

Sub ProcessModule(TheModule As Module, MyTreeView As Object, ParentNode)
If Not TheModule Is Nothing Then
Debug.Print TheModule.Name
Dim LineCount As Long
LineCount = TheModule.CountOfLines

Dim ModuleNode As Node
Set ModuleNode = MyTreeView.Nodes.Add(&quot;Root&quot;, tvwChild, TheModule.Name, TheModule.Name)

Dim counter As Long
For counter = 1 To LineCount
Dim CurLine As String
CurLine = TheModule.Lines(counter, 1)

If Left(CurLine, 4) = &quot;Sub &quot; Or Left(CurLine, 9) = &quot;Function &quot; Then
AddSub CurLine, MyTreeView, ModuleNode
End If
Next counter
End If
End Sub

Sub FindFunctions(MyTreeView As Object)
Application.Echo False

Dim CurDb As Database
Set CurDb = CurrentDb

Dim ModulesContainer As Container
Set ModulesContainer = CurDb.Containers(&quot;Modules&quot;)

Dim CurDoc As Document
Dim TheModule As Module

Dim ParentNode As Node
Set ParentNode = MyTreeView.Nodes.Add(, , &quot;Root&quot;, &quot;Root&quot;)

For Each CurDoc In ModulesContainer.Documents
Debug.Print CurDoc.Name

On Error Resume Next
Set TheModule = Nothing
DoCmd.OpenModule CurDoc.Name
Set TheModule = Modules(CurDoc.Name)

ProcessModule TheModule, MyTreeView, ParentNode
DoCmd.Close acModule, CurDoc.Name
Next CurDoc

Set CurDoc = Nothing
Set ModulesContainer = Nothing

Set ModulesContainer = CurDb.Containers(&quot;Forms&quot;)

For Each CurDoc In ModulesContainer.Documents
On Error Resume Next
Set TheModule = Nothing
If Not CurDoc.Name = &quot;TheFormWithTheTreeControlInIt&quot; Then
DoCmd.OpenForm CurDoc.Name, acDesign
Set TheModule = Forms(CurDoc.Name).Module

ProcessModule TheModule, MyTreeView, ParentNode

DoCmd.Close acForm, CurDoc.Name, acSaveNo
End If
Next CurDoc

Set CurDoc = Nothing
Set ModulesContainer = Nothing

Application.Echo True
End Sub
[/tt]

2) Add this to the form's OnLoad event:

[tt]
Private Sub Form_Load()
FindFunctions Me.TheTreeCtrl
End Sub
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top