• Solve Sql String

    • This topic has 4 replies, 4 voices, and was last updated 11 years ago.
    Author
    Topic
    #493959

    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?

    Viewing 3 reply threads
    Author
    Replies
    • #1445477

      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?

    • #1445561

      We would not need mutiple criterias fortunately.

    • #1445564

      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.

    • #1451018

      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.

    Viewing 3 reply threads
    Reply To: Solve Sql String

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: