Updating cell values on sheet based on selected combo box value
Hi all, I have a sub that populates a combo box based on a retreived
SQL Server 2000 value. This works fine, but I'm not sure how to go
about updating other controls or cells on the page based on this value.
So if the user selects a different order number in this case, different
values which correspond to this order number will appear. Here is my
sub, thanks in advance, Buster.
Public Sub PopulateControl()
Dim cnRetailData As ADODB.Connection
Dim rsRetailData As ADODB.Recordset
Dim strCnn As String
' Open connection.
strCnn = "Provider=sqloledb; Data Source=TEST;Initial
Catalog=TESTDB;" & _
"User Id=xx;Password=xxxxx; "
Set cnRetailData = New ADODB.Connection
cnRetailData.Open strCnn
' Open Orders table.
Set rsOrders = New ADODB.Recordset
rsOrders.CursorType = adOpenKeyset
rsOrders.LockType = adLockOptimistic
rsOrders.Open "Orders", cnRetailData, , , adCmdTable
' Moves to the first record in the record set.
rsOrders.MoveFirst
' Loops through each entry in the record set and adds the last name
' for each entry into the combo box.
Do Until rsOrders.EOF
ActiveSheet.ComboBox1.AddItem rsOrders!order_number
' To use a ListBox control, use the following statement instead
' of the one above:
' UserForm1.ListBox1.AddItem rsOrders!order_number
'
' If the ComboBox or ListBox is on a worksheet instead of
' a UserForm, reference the worksheet instead of the UserForm:
' ActiveSheet.ComboBox1.AddItem rsOrders!order_number
rsOrders.MoveNext
Loop
' Displays the user form. You don't need this if you are not using
' a UserForm object.
'UserForm1.Show
' Closes the table.
rsOrders.Close
' Closes the connection.
cnRetailData.Close
End Sub
|