I have a table of data in Excel and I'm building a userform with two combo boxes on it. I want to show unique items from a column in the first combo box and, when they select an item, to show corresponding unique items in the 2nd combo box.
I'm using the Advanced Filter feature at the moment to draw the unique data I need. However, I think it would be easier to use ADO and use simple SQL statements on the Excel data.
Is there a simple connection string that I can use when drawing data within the same worksheet? Or do I need to use the following example:
Code: Select all
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Andy G\My Documents\Excel Staff.xls;" _
& "Extended Properties='Excel 8.0;HDR=Yes';" ' could add HDR=Yes;IMEX=1';"
cnn.Open ' setting the ConnectionString doesn't open the connection.
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM TestStaff;", cnn, adOpenStatic 'staff is a range name
' or FROM [Sheet1$A1:H20];