Private Sub UserForm_Initialize() PopulateEditorNameComboBox() End Sub Public Sub PopulateEditorNameComboBox() For i = 1 to EditorNameCollection.Count me.cboEditor.AddItem (EditorNameCollection.item(i)) 'Add item to combo box on indicated form Next i End Function
Well, not quite sure what you are trying to attempt.. but I see a few things.
a) There is NO need for a function, your not sending a return value.
so
as for the Form. IF its all in the same CLASS, just use me.
Are you suggesting that sub UserForm is a Different form than THISForm?
Private Sub UserForm_Initialize() PopulateEditorNameComboBox() End Sub Public Sub PopulateEditorNameComboBox() For i = 1 to EditorNameCollection.Count me.cboEditor.AddItem (EditorNameCollection.item(i)) 'Add item to combo box on indicated form Next i End Function
There are many methods to pass data between forms if that is what you are doing...
Delegates / Properties /contructor / object
Public Function LoadCombobox(comboBox As ComboBox) As Boolean ' do whatever. End Function ' call the method from the form. LoadComboBox(Me.theCombobox)
Since the method is loading a combobox, pass in the combobox, not the form. If you pass in the form then the method will not know which control on the form it should be loading.
Public Function LoadCombobox(comboBox As ComboBox) As Boolean ' do whatever. End Function ' call the method from the form. LoadComboBox(Me.theCombobox)
What does your PopulateComboboxes method look like now? You should have changed the method definition to take a combobox as a parameter and also updated the code to reference this parameter. Something like this:
Public Function PopulateComboxes(combobox as Combobox)
combobox.AddItem("hello")
combobox.AddItem("world")
End Function
Here's an mxd (version 9.3.1) that contains two user forms and module with a public method for loading a combobox. Both of the forms call this method in their Initialize event. Hopefully this will help!