Send a specific control to a subroutine

E

ES

I am trying to create a subroutine that I can use to populate specific
listboxs depending on where the user is in the application. I can make it
work by reusing the code in several places but I would prefer to call a
single routine from all the locations. I am having trouble getting the
specific control into a parameter of the subroutine.

Public Sub SelectFiles(ListBox As Control)
[Office.FileDialog code]

For Each varFile In .SelectedItems
ListBox.AddItem varFile
Next
End sub

Private Sub cmdSelectFile_Click()
SelectFiles (Me.lstFilesToLoad)
End Sub

I know it is not correct but I always struggle when trying to refer to
specific objects in code. I just can not get it clear in my head how objects
have to be referred to in a variable.

Any pointers would be greatly appreciated.
 

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