Results 1 to 2 of 2

Thread: Access database search using dbCombo

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 1999
    Location
    Littlehampton, W Sussex GB
    Posts
    203

    Post

    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?

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Posts
    239

    Post

    In your search, have you "Ordered By Record_Number"? Then used a search string to
    verify your selection?

    The following Loads the ComboBox:

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width