Click here to Skip to main content
15,948,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to connect to multiple modules which have different rules per department.

I have a department combobox which hosts the names of the department

the name corresponds to the Module name

so if I pick Finance department

callbyname(finance, "Process", CallType.Method)

but when I try this I get-

System.MissingMemberException: 'Public member 'finance_Process' on type 'String' not found.'

What am I doing wrong?

What I have tried:

I researched callbyname there seems to be a decent amount on a form using Me as the reference point. However, not much on how to access a module from a form using callbyname.
Updated 24-Nov-22 22:59pm

1 solution

The CallByName function[^] exists purely for background-compatibility with VB6. It can only call members on an instance of a class; it cannot call Shared members - which is what all members of a module are - because VB6 didn't have such members.

You're going to need to use reflection instead, which is what CallByName uses behind the scenes:
Reflection - Visual Basic | Microsoft Learn[^]

Dim moduleType As Type = Type.GetType(finance)
If moduleType Is Nothing Then Throw New InvalidOperationException("Module '" + finance + "' not found.")

Dim methodInfo As MethodInfo = moduleType.GetMethod("Process", BindingFlags.Public Or BindingFlags.Static)
If methodInfo Is Nothing Then Throw New InvalidOperationException("Module '" + moduleType + "' does not contain a method called Process.")

methodInfo.Invoke(Nothing, Array.Empty(Of Object)())
Share this answer
Member 11856456 25-Nov-22 6:15am    
Richard, It is not finding the module finance. Dim moduleType As Type = Type.GetType(finance) I am using finance as a string variable. is this supposed to be something else? Maybe a specific object, or should a string variable work?
Richard Deeming 25-Nov-22 6:17am    
Yes, it should be a string containing the type name of the module. You may need to include the namespace.
Richard Deeming 25-Nov-22 6:19am    
Type.GetType Method (System) | Microsoft Learn[^]
"The assembly-qualified name of the type to get... If the type is in the currently executing assembly ... it is sufficient to supply the type name qualified by its namespace."
Member 11856456 25-Nov-22 6:29am    
thanks this really helps out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900