Searching the data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KK

    Searching the data

    hello everyone..

    i want to search the data in my database word by word. I mean if i put
    the something like this in the search textbox "age cellphone date" i
    get the list of the every column n row containing the words "age
    cellphone date"

    is it possible to write such query, plz help me on this and tell me
    what things are feasible and if this is not feasible wat are its
    alternatives?


    Thanks
    K
  • Salad

    #2
    Re: Searching the data

    KK wrote:
    hello everyone..
    >
    i want to search the data in my database word by word. I mean if i put
    the something like this in the search textbox "age cellphone date" i
    get the list of the every column n row containing the words "age
    cellphone date"
    >
    is it possible to write such query, plz help me on this and tell me
    what things are feasible and if this is not feasible wat are its
    alternatives?
    >
    Thanks
    K
    If using something beyond A97, this will get you started. Copy this
    code into a code module and run it to see the result.

    I have a variable called strAndOr. If you passed 3 search words but you
    want to see the row if any of the words match, use Or. If all words
    must match, use And.

    Sub Test()
    Dim s() As String
    Dim i As Integer
    Dim strFilter As String
    Dim strFieldName As String
    Dim strAndOr As String
    Dim intLen As Integer
    Dim strSQL As String

    '"And" where all words in field to be searched must match
    '"Or" for one of the words must match
    'Change to "And" or "Or" depending on type of search
    strAndOr = "And"

    'get the length or And/Or. Used to remove training word
    intLen = Len(strAndOr) + 2


    'the field name to search. Can be passed as argument
    strFieldName = "Address"

    'break out the words to search
    s = Split("age cellphone date", " ")

    'create the filter string
    For i = 0 To UBound(s)
    strFilter = strFilter & strFieldName & " Like *" & _
    s(i) & "* " & strAndOr & " "
    Next i

    'Create SQL string
    strSQL = "Select * From Customer "

    'now remove the and/or at end of filter string
    If strFilter "" Then strSQL = strSQL & "Where " & _
    Left(strFilter, Len(strFilter) - intLen)

    'display the SQL if you'd like
    MsgBox strSQL

    'process however
    '...

    End Sub

    I C U


    Comment

    • KK

      #3
      Re: Searching the data

      thks for ur reply

      the above code u hv mentioned is in which language? i mean m using JSP
      to retrieve data from Access...

      Comment

      • Linq Adams via AccessMonster.com

        #4
        Re: Searching the data

        Then you should have mentioned this fact in your original post, which in
        point of fact needs to be posted in a JSP forum/newsgroup, not in an Access
        forum!

        The code given is Access/VBA.

        --
        There's ALWAYS more than one way to skin a cat!

        Answers/posts based on Access 2000/2003

        Message posted via AccessMonster.c om


        Comment

        • KK

          #5
          Re: Searching the data

          but JSP is da frontend.. my backend is MS Access and thus i posted my
          query here..

          Comment

          • Benny Andersen

            #6
            Re: Searching the data

            On Fri, 20 Jun 2008 16:14:17 -0700 (PDT), KK wrote:
            thks for ur reply
            >
            the above code u hv mentioned is in which language? i mean m using JSP
            to retrieve data from Access...
            it is vba, a basic dialect, which is host language for ms-access and other
            ms-office products. As a programming person, you do not even have to use
            your creative gen to figure out that salad's sequence of assignments just
            shows you the sql syntax you are asking for. As you can see, vba is both
            clumsy (lacks +=), and overillustrativ e (for i=0 to ..). In some repsect
            shorter then pure OO languages like java because af a rich set of statement
            and a single global scope. Beeing left in flavor of .net, it lacks modern
            paradigms like e.g. iterators and generics that Sun Microsystem with java 6
            has blessed us with.
            --
            Benny Andersen

            Comment

            • Linq Adams via AccessMonster.com

              #7
              Re: Searching the data

              >but JSP is da frontend.. my backend is MS Access

              So the only thing "Access" you're using is the table's data. The front end
              is where you're going to have to run your search.

              --
              There's ALWAYS more than one way to skin a cat!

              Answers/posts based on Access 2000/2003

              Message posted via http://www.accessmonster.com

              Comment

              • Tom van Stiphout

                #8
                Re: Searching the data

                On Sat, 21 Jun 2008 00:39:40 -0700 (PDT), KK
                <Kartikeya.Karn atak@gmail.comw rote:

                You are correct to post here. In your JSP language you need to
                construct the SELECT statement:
                select * from SomeTable
                where SomeField like '*SomeWord*' or SomeField like
                '*SomeOtherWord *'
                etc.

                Then you need to use your language to execute this statement against
                the Access database. I've never used JSP but I presume there is a way
                to use ADO, and create an ADODB.Recordset object. A JSP-related
                newsgroup can help you with the finer points of that.

                -Tom.


                >but JSP is da frontend.. my backend is MS Access and thus i posted my
                >query here..

                Comment

                • Salad

                  #9
                  Re: Searching the data

                  KK wrote:
                  but JSP is da frontend.. my backend is MS Access and thus i posted my
                  query here..
                  I commented my code more than I normally would in this forum because I
                  figured you were a beginner. I'm surprised that you could not study my
                  code and determine how to modify it in your java dialect. You might be
                  better off turning over your project to a programmer.

                  Comment

                  Working...