Click to See Complete Forum and Search --> : Access database search using dbCombo
Caro
Jan 4th, 2000, 02:05 AM
I am using a DBCombo control to search for a company name in a table. I can drop down OK and get a list of names alphabetiaclly but when I click on one for selection, I update a different record with the name selected. I think the one I update is the one I stared with. Any ideas as to where I'm going wrong?
johnpc
Jan 4th, 2000, 11:28 AM
In your search, have you "Ordered By Record_Number"? Then used a search string to
verify your selection?
The following Loads the ComboBox:
Private Sub LoadcboBox()
' Add items to the ComboBox
Dim strSQL As String 'Must put in each Sub that makes a SQL Call
strSQL = "SELECT "
strSQL = strSQL & "* FROM "
strSQL = strSQL & "tblItems "
strSQL = strSQL & "ORDER BY Record_Number"
Set oRS = New Recordset
oRS.Open strSQL, goConn, adOpenStatic, adLockReadOnly
'To load a combobox with values from a database, we can use
'a special control (the datalist control - see under project
'components) or by using objects. Loop through each value
'in the recordset and use the .AddItem method for filling
'in the combobox.
With oRS
.MoveFirst
Do Until .EOF
cboBox1.AddItem !Record_Number
.MoveNext
Loop
.Close
End With
End Sub
'''''''''''''''''''''''''''''''''''
'Now that the ComboBox is loaded
'Get what we want
''''''''''''''''''''''''''''''''''
Private Sub cboBox1_Click()
'Search the databse for the proper Item
Dim strSQL As String 'Must put in each Sub that makes a SQL Call
'Set the SearchString through the ComboBox
strSearchString = Box1
strSQL = "SELECT "
strSQL = strSQL & "* FROM "
strSQL = strSQL & "Item"
strSQL = strSQL & "ORDER BY Record_Number"
Set oRS = New Recordset
oRS.Open strSQL, goConn, adOpenStatic, adLockReadOnly
Dim RecNo as Integer
With oRS
.Find "Record_Number = '" & SearchString & "'"If Not (.EOF) Then
'This is what we are looking for
RecNo= !AnotherField
End If
.Close
End With
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.