Public Sub PopulateCombos(myForm As Form) Dim mySQL As String = "" Dim myDispMember As String Dim myValue As String Dim x As Integer = 0 'Call the SQL.Exceute query - query goes in the the parentheses 'loop through all the combo boxes For Each myCombo As ComboBox In myForm.Controls.OfType(Of ComboBox).ToArray 'reset the strings mySQL = "" myDispMember = "" myValue = "" MsgBox(myForm.Name) MsgBox(myCombo.Name) MsgBox(myForm.Controls.OfType(Of ComboBox).Count()) x = x + 1 MsgBox(x) Select Case myCombo.Name.ToString Case "cboClient" 'populate client list mySQL = "SELECT id, strSname, strFName FROM tblContacts" myDispMember = "strSName" myValue = "id" Case "cboStatus" 'Populate cboStatus mySQL = "SELECT id, strProjStatus FROM tblProjectStatus" myDispMember = "strProjStatus" myValue = "id" End Select SQL.ExecQuery(mySQL) If SQL.SQLDS.Tables.Count > 0 Then With myCombo .DisplayMember = myDispMember .ValueMember = myValue .DataSource = SQL.SQLDS.Tables(0) .AutoCompleteMode = AutoCompleteMode.SuggestAppend .AutoCompleteSource = AutoCompleteSource.ListItems End With End If Next i End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)