Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making a generic combo box filling routine how to pass the combo box name

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
0
36
US
How can I replace the yellow highlight with the variable "[highlight #8AE234]whichComboBox[/highlight]" which will have something like "cboChooseXXX"
Code:
    Private Sub LoadComboBox(ByVal [highlight #8AE234]whichComboBox[/highlight], ByVal SQLString, ByVal AddFirstItem)
        ' call this like so
        ' Call LoadComboBox(Me.cboChooseProcedure.Name)
        'clear it first
        [highlight #FCE94F]Me.cboChooseProcedure[/highlight].Items.Clear()

        Dim strConn As New SqlConnection(gblConnectionString)
        Dim objComm As SqlCommand
        Dim objReader As SqlDataReader
       strConn.Open()
        objComm = New SqlCommand(SQLString, strConn)
        objReader = objComm.ExecuteReader()
        If AddFirstItem <> "" Then
            [highlight #FCE94F]Me.cboChooseProcedure[/highlight].Items.Add(AddFirstItem)
        End If
        If objReader.HasRows Then
            Do While objReader.Read()
                [highlight #FCE94F]Me.cboChooseProcedure[/highlight].Items.Add(objReader.GetString(0))
            Loop
        End If
       'select 1st item in list
        [highlight #FCE94F]Me.cboChooseProcedure[/highlight].SelectedIndex = 0
    End Sub

DougP
 
Don't pass in a name, pass in the actual combobox. Also in you procedure definition, declare what you are passing in, using As string, or as dropdownlist... etc.
then in your code use whichComboBox.Items.Clear()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top