How to display the field in text box using combo box. When the user click the combo box, two fields will be displayed, the first field will be displayed in 1st text box1 and 2nd field in text box2.

These are my codes. Can you help me how?

Dim cmdoff As ADODB.Command
Dim rsoff As ADODB.Recordset

Private Sub loadOffice()
Set cmdoff = New ADODB.Command
Set cmdoff.ActiveConnection = Conn

cmdoff.CommandText = "SP_POPULATE_OFFICECODE"
cmdoff.CommandType = adCmdStoredProc
Set rsoff = cmdoff.Execute
Combo1.Clear
With rsoff
.MoveFirst
Do While Not rsoff.EOF

Combo1.AddItem !Office_Code '& vbTab & !Office_Title
Text1.Text = !Office_Title

.MoveNext
Loop

End With
cmdoff.ActiveConnection = Nothing

End Sub

Private Sub Combo1_DropDown()
Call loadOffice
End Sub

Private Sub Form_Load()
con = OpenConnect(Conn)

End Sub

In combobox selected index changed event get the selected item and set it to textbox

is this code running well? i mean, this code can display data to combo box?

Combo1.AddItem !Office_Code '& vbTab & !Office_Title

You use vbtab to separate data. is that working?
I think VbTab not working to separate it.
You can use space or commas (or other sign) .

Combo1.AddItem !Office_Code & " " & !Office_Title ' Separate With Space
Combo1.AddItem !Office_Code & "," & !Office_Title ' Separate With Commas

How to display the field in text box using combo box. When the user click the combo box, two fields will be displayed, the first field will be displayed in 1st text box1 and 2nd field in text box2.

Okay, you can display it on combobox click event. Use split to separate data in combo box with delimiter is space or commas (or other sign that you used to separated in combo box).

Private Sub Combo1_Click()
    Dim temp As Variant
    temp = Split(Combo1.Text, " ") ' Split it with space delimeter, store it as array in temp.
    ' Accessing separated data on temp variable
    Text1.Text = temp(0) 
    Text2.Text = temp(1)
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.