0
Hello, I would like to insert in a combobox the Item and the index of that Item.
The item (function_name) I do through a query in a database and I wanted the index to be the working id_function.
I’ve tried several ways and I haven’t been able to.
Note: The error it causes is "It was expected: = "
Follow the Code below.
Private Sub UserForm_Initialize()
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Dim TotalCursos As Variant
'Parametrização do Banco de Dados
Set cn = New ADODB.Connection
strDB = ThisWorkbook.Path & "\SistemaGerenciamento.accdb"
cn.ConnectionString = _
"Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strDB & ";"
cn.Open
strSQL = "SELECT id_funcionario, nome_funcionario FROM tbl_funcionario"
Set rs = cn.Execute(strSQL)
Do While Not rs.EOF
cmb_funcionario.AddItem (rs("nome_Funcionario"),rs("id_funcionario"))
rs.MoveNext
Loop
cn.Close
End Sub