CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2001
    Posts
    29

    Search and display record.. Urgent! (Source code provided)

    I have a customer form and a search form. if user enters customer id and a record is found, how am i going to display them on the customer form and re-assign the record pointer? Below code belongs to the command "Search" on Search form.


    private Sub cmdSearch_Click()
    Dim cnn as new ADODB.Connection
    Dim rst as new ADODB.Recordset
    Dim mark as Variant
    Dim count as Integer

    count = 0
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ims.mdb;Persist Security Info=false"
    rst.Open "SELECT CustomerId FROM Customers", cnn, adOpenStatic, adLockReadOnly, adCmdText

    ' The default parameters are sufficient to search forward
    ' through a Recordset.

    rst.Find "CustomerId LIKE '" & txtCustomerID.Text & "'"

    ' Skip the current record to avoid finding the same row repeatedly.
    ' The bookmark is redundant because Find searches from the current
    ' position.

    Do While rst.EOF <> true 'Continue if last find succeeded.
    count = count + 1 'Count the last title found.
    mark = rst.Bookmark 'Note current position.
    rst.Find "CustomerId LIKE '" & txtCustomerID.Text & "'", 1, adSearchForward, mark
    Loop
    If count = 0 then
    MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation
    else


    'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT


    End If
    Unload me

    rst.Close
    cnn.Close

    End Sub





  2. #2
    Join Date
    Apr 2001
    Posts
    23

    Re: Search and display record.. Urgent! (Source code provided)


    MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

    else

    frmCustomer.TxtFind = CustomerID

    'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
    End If
    Unload me
    rst.Close
    cnn.Close
    End Sub







  3. #3
    johnpc7 Guest

    Re: Search and display record.. Urgent! (Source code provided)


    MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

    else

    frmCustomer.TxtFind = CustomerID

    'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
    End If
    Unload me
    rst.Close
    cnn.Close
    End Sub







  4. #4
    Join Date
    Jun 2001
    Posts
    29

    Re: Search and display record.. Urgent! (Source code provided)

    According to your code, this will only display the customer Id. What about Customer Name, Customer Address, telephone, etc? I also want to show them all in frmCustomer too!


  5. #5
    Join Date
    Apr 2001
    Posts
    23

    Re: Search and display record.. Urgent! (Source code provided)

    Just put the required number of text boxes on the
    form and code as below. If you would like to see
    this method in an application go to:
    http://johnpc.freeservers.com
    and download the ADOTotals Program.


    MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

    else
    with frmCustomer
    .TxtFind = CustomerID
    .TxtCustomerName = Customer Name
    .TxtCustomerAddress = Customer Address
    .TxtCustomerTelephone = Customer Telephone
    End With

    'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
    End If
    Unload me
    rst.Close
    cnn.Close
    End Sub













  6. #6
    johnpc7 Guest

    Re: Search and display record.. Urgent! (Source code provided)

    Just put the required number of text boxes on the
    form and code as below. If you would like to see
    this method in an application go to:
    http://johnpc.freeservers.com
    and download the ADOTotals Program.


    MsgBox "Customer Id not found: " & txtCustomerID.Text, vbInformation

    else
    with frmCustomer
    .TxtFind = CustomerID
    .TxtCustomerName = Customer Name
    .TxtCustomerAddress = Customer Address
    .TxtCustomerTelephone = Customer Telephone
    End With

    'THIS is WHERE THE CODE NEEDED, BUT I DON'T KNOW WHAT to PUT
    End If
    Unload me
    rst.Close
    cnn.Close
    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

Featured