CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Searching

  1. #1
    Join Date
    Sep 2001
    Posts
    7

    Searching

    hello,

    i am creating an application where i search for a phone number in a database created using access 2000. i am using ado. i have tried so many different thigns to get my search to work and have failed miserably. any help from anyone would be greatly appreciated.

    thanks



  2. #2
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Searching

    Post what you have, somebody can help.

    David Paulson


  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Searching

    This could be an example, cnn is an open ADODB.Connection

    set rst = cnn.execute("SELECT * FROM People WHERE PhoneNo = '555-5555'")



    This returns all the records from the People table, where the PhoneNo is 555-5555

    OR

    set rst = new ADODB.Recordset
    rst.open "People", cnn
    rst.Filter = "PhoneNo='555-5555'"



    Does the same as the first, but probably slower, cause this opens the entire table. This will be faster if you need to search multiple times

    OR

    set rst = new ADODB.Recordset
    rst.open "People", cnn
    rst.Find "PhoneNo='555-5555'"



    The last one will go to the first mathing record, starting from the current position

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  4. #4
    Join Date
    Sep 2001
    Posts
    7

    Re: Searching

    Hello,

    this is the code that i have so far(see below). It works. it finds the record. the only problem is once it finds it, i cannot browse other records when i hit NEXT or Previous.

    I get an error message saying "The changes u requested to the table were not succesfull becasue they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicated data, remove the index, or redefine the index to permit duplicate entries and try again"


    Private Sub Command5_Click()

    'Search procedure for a Record

    Dim sql As String
    Dim msgretval As Integer

    Dialog.Show vbModal
    On Error GoTo errlabel

    sql = "SELECT * FROM CUSTOMERS WHERE PHONE = '" & Dialog.Text1.Text & "';"
    Unload Dialog
    Set Dialog = Nothing
    Set cnCustomer = New ADODB.Connection
    cnCustomer.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=E:\RESTAURANT\customer.mdb"

    cnCustomer.Open
    Set rsCustomer = New ADODB.Recordset
    rsCustomer.Open sql, cnCustomer, adOpenDynamic

    If rsCustomer.BOF And rsCustomer.EOF Then
    MsgBox "Customer NOT FOUND"
    End If


    Text1.Text = rsCustomer![firstname]
    Text2.Text = rsCustomer![lastname]
    Text3.Text = rsCustomer![phone]
    Text4.Text = rsCustomer![address]
    Text5.Text = rsCustomer![city]
    Text6.Text = rsCustomer![State]
    Text7.Text = rsCustomer![zip]
    Text8.Text = rsCustomer![notes]
    Exit Sub


    The code for browsing the NEXT record is:

    Private Sub Command6_Click()
    'Module for browsing on to the next record
    On Error GoTo errlabel
    If Not Adodc1.Recordset.EOF Then
    Adodc1.Recordset.MoveNext
    End If
    If Adodc1.Recordset.EOF And Adodc1.Recordset.RecordCount > 0 Then
    Adodc1.Recordset.MoveLast
    End If
    Exit Sub

    errlabel:
    MsgBox Err.Description
    End Sub

    Thanks in advance




  5. #5
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Searching

    I'm sorta lost with your code. Have you created a recordset (rsCustomer) and using an adodc control also? Please explain to me what you are trying to accomplish with each.

    David Paulson


  6. #6
    Join Date
    Sep 2001
    Posts
    7

    Re: Searching

    thanks but i figured it out. i just had to unload and reload the form and it works.

    thanks though. appreciate it.



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

Featured