January 6th, 2000, 03:23 AM
I am using ADO. I have 1 combo box and 7 textboxes on my form. On the basis of selecting any item
in combo box i want to fill all the 7 text boxes with the data related to the item selected in combo box.
I am getting the list of items in combobox from the SQL Server data.
if anybody can help providing sample code....
thanks in advance
sanjay
sonman
January 17th, 2000, 05:44 PM
Try something like this.
on error GoTo Errors
set db = new Connection
db.CursorLocation = adUseClient
db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=E:\training\WinPrism ODBC Database\WinPrismData.mdb;"
set adoPrimaryRS = new Recordset
adoPrimaryRS.Open "select StoreID,ODBCDriver,UserID,Password,IPAddress,Server from StoreLocations", db, adOpenStatic, adLockOptimistic
Dim sql as string 'Declare a string to hold the SQL statement
cboBox.Clear
'Clear the combobox in question, in case it isn't
sql = ""
'Clear SQL in case there is another var named SQL somewhere
'Setup SQL to select fields based on the values passed to the function
sql = "SELECT " & IDField & descField & " FROM " & strTB
With adoPrimaryRS
Do Until .EOF 'Loop until the End of the recordset
'Add the items to the combo box
cboBox.AddItem adoPrimaryRS(descField)
cboBox.ItemData(cboBox.NewIndex) = adoPrimaryRS(IDField)
.MoveNext
Loop
.MoveFirst
.Close
End With
'set adoPrimaryRS = nothing 'Release the variable
cboBox.ListIndex = 0
Exit Sub
Errors: 'error handler
If Err.Number <> 0 then
MsgBox ("error #: " & Str(Err.Number) & Err.Description)
Exit Sub
End If