Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Search or filter records on a form [modified]

Search or filter records on a form [modified]

Scheduled Pinned Locked Moved Visual Basic
databasetutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    penguin5000
    wrote on last edited by
    #1

    Wonder if any of you guys could point me in the right direction? Everywhere I've searched on Google always shows me how to do this with a datagrid - but not a form - and it just doesn't seem to want to work how I want it work. I've created a form which correctly displays all my fields in a recordset. I can scroll through them, add new records, delete records, etc. etc. and everything is fine. I now want to add a Search field to the form so that when the user enters a search string, it automatically searches through the dataset for EITHER the CompanyName OR the CompanyID - and refreshes the display to display the appropriate search result (ie. populates the currently open form with the appropriate record). -- modified at 18:21 Wednesday 31st May, 2006 I partly figured it out - but can't get it to work with an OR part of the SQL. Any advice would be appreciated. The CompanyID is an Autonumber field. Dim strSearch As String = "SELECT * FROM tblCustomersParent WHERE CustomerName Like '%" & txtSearchString.Text & "%'" Me.OleDbSelectCommand1.CommandText = strSearch Me.LoadDataSet()

    M 1 Reply Last reply
    0
    • P penguin5000

      Wonder if any of you guys could point me in the right direction? Everywhere I've searched on Google always shows me how to do this with a datagrid - but not a form - and it just doesn't seem to want to work how I want it work. I've created a form which correctly displays all my fields in a recordset. I can scroll through them, add new records, delete records, etc. etc. and everything is fine. I now want to add a Search field to the form so that when the user enters a search string, it automatically searches through the dataset for EITHER the CompanyName OR the CompanyID - and refreshes the display to display the appropriate search result (ie. populates the currently open form with the appropriate record). -- modified at 18:21 Wednesday 31st May, 2006 I partly figured it out - but can't get it to work with an OR part of the SQL. Any advice would be appreciated. The CompanyID is an Autonumber field. Dim strSearch As String = "SELECT * FROM tblCustomersParent WHERE CustomerName Like '%" & txtSearchString.Text & "%'" Me.OleDbSelectCommand1.CommandText = strSearch Me.LoadDataSet()

      M Offline
      M Offline
      mr_12345
      wrote on last edited by
      #2

      Are you trying to do a like on the auto number field? "SELECT * FROM tblCustomersParent WHERE CustomerName Like '%" & txtSearchString.Text & "%' or CompanyID = " & txtCompanyName You should really look at using parameterized queries as well. Mike Lasseter

      P 1 Reply Last reply
      0
      • M mr_12345

        Are you trying to do a like on the auto number field? "SELECT * FROM tblCustomersParent WHERE CustomerName Like '%" & txtSearchString.Text & "%' or CompanyID = " & txtCompanyName You should really look at using parameterized queries as well. Mike Lasseter

        P Offline
        P Offline
        penguin5000
        wrote on last edited by
        #3

        Hi - yes, the query was pretty much like you've suggested. I had tried: "Select * From tblCustomersParent Where CompanyName Like '%" & txtSearchString.Text & "%'" & _ " or CompanyID Like '%" & txtSearchString.Text & "%'" and then... "Select * From tblCustomersParent Where CompanyName Like '%" & txtSearchString.Text & "%'" & _ " or CompanyID Like " & txtSearchString.Text ... and ended up just commenting out the OR bit :sigh: What do you mean when you say, "parameterized queries"? Could you show me an example?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups