Mike
Mike

Reputation: 1938

How to fill a listbox with an array filled in module1 VBA

I'm new to creating user forms in VBA. I've been using VBA macros for a while now though so I understand some about them. Right now I'm creating a spreadsheet for a user where I'm using a user form with a list box. I have a lot of code in a regular module and need to refernce the module to fill the listbox. What I have right now is this:

Private Sub StartButton_Click()
 Dim Number
 Call GetTellerNames
 For Number = 0 To 40 Step 1
    If GetTellerNames(Number) <> "" Then
        ListBox1.AddItem (GetTellerNames(Number))
    End If
 Next
End Sub

When I run this I get an error saying

Sub of Function not defined

How do I fix this so that I can use the array in my module to fill the list box? I've already got the code to fill the array working.

Here is the code for the GetTellerNames sub in the module:

Private Function GetTellerNames()
GetTellerNames = FindOthers(BranchNumber, TellerCode, 2)
End Function

It is using global variables that are set in other parts of the code. I can post all of the code if necessary.

Upvotes: 2

Views: 5614

Answers (1)

user2140173
user2140173

Reputation:

Since the GetTellerNames() code lies within a standard module you need to change the access modifier to public in order to be able to access that method/sub from the UserForm1 object module.

Upvotes: 1

Related Questions