Crazy Ideal. List of functions.

G

Guest

The situation:
We have a program that imports files. (different types, different formats)
There is one button per company.
You press the button for the company file you won't to import.
On Click says "Call Import-ASI" or
"Call Import-PPS" or
"Call Import-GLC" or ext. ext. ext.

The Crazy part.
Keep in mind that you can use the MsysObjects to get a list of tables,
forms, reports. ext. ext.

The Question:
Is there a way to get a list of function that are currently in a program?
The Ideal is to replace the buttons with a list box.
I can use "Import-" as a filter. All the import function have "Import-" in
them.

Scott Burke
 
G

Guest

Scott Burke said:
The situation:
We have a program that imports files. (different types, different formats)
There is one button per company.
You press the button for the company file you won't to import.
On Click says "Call Import-ASI" or
"Call Import-PPS" or
"Call Import-GLC" or ext. ext. ext.

The Crazy part.
Keep in mind that you can use the MsysObjects to get a list of tables,
forms, reports. ext. ext.

The Question:
Is there a way to get a list of function that are currently in a program?
The Ideal is to replace the buttons with a list box.
I can use "Import-" as a filter. All the import function have "Import-" in
them.

Scott Burke


If I understand this correctly you want the following:

for i = 0 to Access.Modules.Count - 1
Access.Modules.items(i).Name
next i
 
D

Dirk Goldgar

Ollie said:
If I understand this correctly you want the following:

for i = 0 to Access.Modules.Count - 1
Access.Modules.items(i).Name
next i

I don't think that's quite right. However, the help entry for the
ProcOfLine Property, in the help book "Microsoft Access Visual Basic
Reference", gives a function to list all procedures in a particular
module. That, combined with code to loop through all the modules in the
current project:

Dim ao As AccessObject

For Each ao In CurrentProject.AllModules
Debug.Print ao.Name
Next ao

could be part of a solution.
 
D

Dirk Goldgar

Scott Burke said:
I Dirk. Nice try. I could only get the module names.
I keep looking.

You didn't read all of my message. The code I posted was just an
example of how to loop through all the modules in the database. Getting
the procedure names from each module is more complicated, but a function
to do it is in the help article I referred to.
 
G

Guest

What you are looking for is not really what you want. I would suggest a
change in your strategy.
Instead of a list of functions in a List box, I would suggest a combo box of
companies. Then create one import sub or function you pass the name or code
of the company you want to import:

Call ImportCompanies(Me.MyCombo)

Then write one function with a Select Case statement to perform the import
for that company:

Sub ImportCompanies(strCompany as String)

Select Case strCompany
Case "ASI"
'Do your import specific to ASI Here
Case "PPS"
'Do your import specific to PPS Here
Case "GLC"
'Do your import specific to GLC Here
End Select
 
G

Guest

Scott Burke said:
I Dirk. Nice try. I could only get the module names.
I keep looking.

Scott Burke


This is a long shot, but ....

for i = 1 to access.modules.count - 1
for j = 1 to access.modules.procCountLines
debug.print (access.modules(i).ProcOfLine(j,vbext_pk_Proc)
next j
next i
 
D

Dirk Goldgar

Klatuu said:
What you are looking for is not really what you want. I would
suggest a change in your strategy.
Instead of a list of functions in a List box, I would suggest a combo
box of companies. Then create one import sub or function you pass
the name or code of the company you want to import:

Call ImportCompanies(Me.MyCombo)

Then write one function with a Select Case statement to perform the
import for that company:

Sub ImportCompanies(strCompany as String)

Select Case strCompany
Case "ASI"
'Do your import specific to ASI Here
Case "PPS"
'Do your import specific to PPS Here
Case "GLC"
'Do your import specific to GLC Here
End Select

Good suggestion, Klatuu. Further, if the import functions all have
names that are the same except for the substitution of the company
identifier, one could forego the Select Case structure and use Eval to
run the function by name:

Eval "Import_" & strCompany & "()"
 
D

Dirk Goldgar

Ollie said:
This is a long shot, but ....

for i = 1 to access.modules.count - 1
for j = 1 to access.modules.procCountLines
debug.print (access.modules(i).ProcOfLine(j,vbext_pk_Proc)
next j
next i

That's moving in the right direction, but the application's Modules
collection only contains modules that are currently open in the VB
Editor. Again, see the help file entry I referred to.
 
G

Guest

how about this:
Make a table with two fields.
Acode: ASI
jobcode: Import-ASI

Now.... Fill the combo box with this table. Showing only the Acode. Hide
the Jobcode.
When you select "ASI" I can "call" the function "Import-ASI". ???

will the "Call" handle a string? I am going to check that out.

Scott Burke
 
D

Dirk Goldgar

Scott Burke said:
how about this:
Make a table with two fields.
Acode: ASI
jobcode: Import-ASI

Now.... Fill the combo box with this table. Showing only the Acode.
Hide the Jobcode.
When you select "ASI" I can "call" the function "Import-ASI". ???

will the "Call" handle a string? I am going to check that out.

The Call statement can't take a string argument for the function name.
But, as I pointed out in my previous post, the Eval function can. The
procedure has to be a Function, not a Sub, and the name passed to Eval
must be identified as a function by putting "()" after its name.

You can't use the "-" character in a function name, though. I suggest
you use the underscore character (_) instead.
 
B

Brendan Reynolds

You could use CallByName. The only caveat is that you have to implement your
functions as methods of a class, but that's not difficult. For example, in a
class module (named 'TestClass' for this example) ...

Public Function FirstFunction()
MsgBox "FirstFunction Executed"
End Function

Public Function SecondFunction()
MsgBox "SecondFunction Executed"
End Function

In the AfterUpdate event procedure of a combo box ...

Private Sub Combo0_AfterUpdate()

Dim MyClass As New TestClass
CallByName MyClass, Me.Combo0, VbMethod

End Sub

Private Sub Form_Load()

Me.Combo0.RowSourceType = "Value List"
Me.Combo0.RowSource = "FirstFunction;SecondFunction"
Me.Combo0.LimitToList = True

End Sub

Private Sub Combo0_AfterUpdate()

Dim MyClass As New TestClass

If Len(Me.Combo0 & vbNullString) > 0 Then
CallByName MyClass, Me.Combo0, VbMethod
End If

End Sub
 
D

Dirk Goldgar

Brendan Reynolds said:
You could use CallByName. The only caveat is that you have to
implement your functions as methods of a class, but that's not
difficult.

I thought of that, but I don't see the advantage, in this case, over
just using Eval().
 
B

Brendan Reynolds

There probably isn't one, Dirk. CallByName is more portable, if that's of
concern (it's supported in VB.NET) but of course portability may not be a
concern. I'm just putting it forward as a possible alternative for
consideration, not suggesting that one method is necessarily better than the
other.
 
G

Guest

Thanks everyone for your imput. I am planning to use this ideal in an
upcoming program. I think a table with three fields (Acode,
Pro_name,Deleted) with give me the flexiblity and controll I am looking for.

Thanks again
Scott Burke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top