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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Populate Combo Box with Dynamic SQL Values

Status
Not open for further replies.

sardine53

Programmer
Jul 4, 2003
79
0
0
US
Hello,

Excel 2013, SQL 2008R2

I am hoping this is the right forum and someone could point me in the right direction:

I have a Stored Procedure with a "Customer" parameter linking to an excel spreadsheet.

So far, I have an input box in Excel where the user can type the value and the command button will pull up the proper results:

Private Sub CommandButton1_Click()

Dim Customer As String

Member = Sheets("Sheet1").Range("K8").Value

With ActiveWorkbook.Connections("ABCWEB2 SQLReports sysdiagrams").OLEDBConnection
.CommandText = "EXEC dbo.usrsp_S_Customer_Census '" & Customer & "'"
ActiveWorkbook.Connections("ABCWEB2 SQLReports sysdiagrams").Refresh
End With
End Sub

My goal is to use a Combo Box for the user to select a value. I would like to use the stored procedure or SQL table to bring in the distinct values. As there will be new "Customer"s added frequently it needs to be a dynamic list.

How would I best accomplish this?

Thanks in advance for any assistance!
 
Private Sub ComboBox1_Change()

Dim Customer As String

Member = Sheets("Sheet1").Range("K8").Value

With ActiveWorkbook.Connections("ABCWEB2 SQLReports sysdiagrams").OLEDBConnection
.CommandText = "EXEC dbo.usrsp_S_Customer_Census '" & Customer & "'"
ActiveWorkbook.Connections("ABCWEB2 SQLReports sysdiagrams").Refresh
ComboBox1.ListFillRange = Sheet1.[Table_ExternalData_1].Member

End With
End Sub
 
...and is your combobox an MS Forms control or an ActiveX control?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Try this...
Code:
ComboBox1.ListFillRange = Sheet1.[Table_ExternalData_1[Member]].Address

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I should have been more observant.

Member has only one value; the value in K8?

That does not make sense for a Combobox or am I missing something?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Member is only one column (not Member plus ID or something else)
I am expecting the drop-down to pull up the Member name and associated other columns from the stored procedure.

I was trying to convert the input box (which worked) to a drop down.

I'm probably the one that's missing something! I thought this would be simple.
 
Some suggestions to try...

ComboBox1.ListFillRange = Sheet1.[Table_ExternalData_1[Member]].Address

Or

ComboBox1.ListFillRange = Sheet1.[Table_ExternalData_1].Address

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
...and are you sure the Column Heading in your table has no leading or trailing SPACES?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Tried both with no luck. No leading or trailing spaces in the Column Heading.

Maybe I missing something else? I can still bring in the values using the text box with my initial code/post.
 
Can you upload a representative version of your workbook?

Don’t need the query connection but do need the data/table.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top