Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    505
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solve Sql String

    Hi,

    I have the following code on an afterupdate event for a text box on a form:

    Dim strsearch As String
    Dim strtext As String

    strtext = Me.txtSearch.Value
    strsearch = "SELECT * from tblvaluations where ((surname1 like ""*" & strtext & "*"") or (surname2 like ""*" & strtext & "*"") or (vstreetname like ""*" & strtext & "*"") or (vpostcode like ""*" & strtext & "*"") or (hometel like ""*" & strtext & "*"") or (mobiletel like ""*" & strtext & "*"") or (vstreetname like ""*" & strtext & "*"")or (emailaddress like ""*" & strtext & "*""))"
    Me.RecordSource = strsearch

    However the text box that I want to use to search the information within tblValuations could sometimes have the combination of VHouseNo and Vstreetname. How can I get it to look for the contents of the search box strtext to look at the combined value of vhouseno and vstreetname?
    Best Regards,

    Luke

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,535
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Do I assume that strText is used in all conditions of the where?
    Interesting, I had never done that before, what if you wish to have multiple values to search for?

  4. #3
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    505
    Thanks
    0
    Thanked 0 Times in 0 Posts
    We would not need mutiple criterias fortunately.
    Best Regards,

    Luke

  5. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,496
    Thanks
    3
    Thanked 42 Times in 42 Posts
    If I understand correctly, you are looking at a situation where the user enters the house number and the street name in the same text box. In that case there isn't any easy way to search on both, or either one for that matter. You could write some code to inspect the entered string and see if a portion is numeric, look for a separator character, etc., but it's a pretty ugly process.

    If on the other hand, you want to search on multiple criteria, such as house number and street name, the typical approach is to provide multiple text boxes on the search form. You then construct a SQL statement based on what text boxes have data entered in them, and use the AND condition so that both are met.
    Wendell

  6. #5
    New Lounger
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Let me start by saying searching for txt is never a good idea. If someone accidentally enters two spaces betweem street_number and street name, that data may never be found. Same can be true if space is entered after either name, or any character or punctuation. These should be two separate fiends that are edit constrained. Street number should ONLY accept integers, and name should be left aligned or trimmed.

Posting Permissions

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