As with everything in this forum there are always multiple options available. Here is mine:
1.) Create a module for your application.
2.) Create a public function that passes a combo box
from your form as a parameter and returns a combo box
as a value.
Example:
Module Module1
Public Function fncFillComboBox(ByVal cbo As ComboBox) As ComboBox
'* Simply filling the combobox with numbers.
For intX As Integer = 0 To 5
cbo.Items.Add(intX.ToString)
Next
cbo.SelectedIndex = 0
'* Return the combobox to your calling form.
fncFillComboBox = cbo
End Function
End Module
Assuming a simple example form with a button and a combo box
here is sample code to fill your combo box:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ComboBox1 = Module1.fncFillComboBox(Me.ComboBox1)
End Sub
End Class
You could easily change the example function to pass not only the combo box but also an SQL statement that could be processed within the function.
Best Regards,
Earl Francis