Loading combobox and subsequent textbox from SQL stored procedure

NickySummers

New Member
Joined
Jul 25, 2014
Messages
1
Hi,
I've have the code below to fill a combobox with data from a mySQL stored procedure. The SP selects the customer code and customer name. Depending on what customer code the user chooses, I need to populate a textbox with the associated customer name. Please could somebody help me with the best way to do this?
Thanks very much.

Dim Conn As ADODB.Connection
Dim ConnectionString As String
Dim cmd As ADODB.Command
Dim fld As Variant
Dim Results As ADODB.Recordset
Dim x As Integer
Dim vaData As Variant




'ConnectionString = "Provider=MSDASQL.1;Driver={SQL Server};Server=TestVSQL01\TestSQL01;Database=OptimusBridge;Uid=delta_web_test;Pwd=delta_web_test"
ConnectionString = "Provider=MSDASQL.1;Driver={SQL Server};Server=BI-BRIDGE\SQLExpress;Database=OptimusBridge;Uid=workstream;Pwd=workstream"


Set Conn = New ADODB.Connection


Conn.Open ConnectionString






Set cmd = New ADODB.Command
With cmd
.CommandText = "GetAllClients"
.CommandType = adCmdStoredProc
.ActiveConnection = Conn
End With


Set Results = cmd.Execute


With Results
x = .Fields.Count
vaData = .GetRows
End With


With frmDataInput
With .cboClient
.BoundColumn = x
.List = Application.Transpose(vaData)
.ListIndex = -1
End With
.Show vbModeless
End With


Results.Close
Set Results = Nothing
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,215,299
Messages
6,124,132
Members
449,143
Latest member
LightArisen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top