Results 1 to 3 of 3

Thread: Search facility

  1. #1
    Join Date
    Oct 2003
    Posts
    15

    Red face Unanswered: Search facility

    I would like to create a search facility so users can type in keywords to find an item in the database. Queries do not allow this as they have to be predefined searches, how can i go about this?

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    I can think of two choices. Use a filter or change the query dynamically.

    Filters:

    stFilter = "[Part1] like '*" & Me![Part1Search] & "*'"
    DoCmd.ApplyFilter , stFilter


    Dynamic queries:

    set dbs as currentdb()
    set qdf = dbs.querydefs("YourParsedQuery")

    if instr(qdf.sql, " WHERE ") > 0 then
    qdf.sql = left(qdf.sql, instr(qdf.sql," WHERE ") -1) & " WHERE " & stYourWhereClause & ";"
    else
    qdf.sql = left(qdf.sql, len(qdf.sql) - 1) & " WHERE " & stYourWhereClause & ";"
    endif
    qdf.execute
    qdf.close

  3. #3
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    > thanks for you help, but if you could put your reply to my
    > post in an english, ...

    The problem is you did not supply much detail about your problem. By a search facility, I must assume you want to create a form that will search for keywords in a query. I have a similar form. I get the user to select a part to show and then the form gets filtered based on that part. Hence the code:

    stFilter = "[Part1] like '*" & Me![Part1Search] & "*'"
    DoCmd.ApplyFilter , stFilter

    On my form, the user selects part 1 from a pulldown list. The name of the pulldown list is Part1Search. The *'s are there so all records will show if the user does not enter anything in the Part1Search field.

    The second solution is much more complex, but I included it incase it helps you or someone else. Try the first solution. If that does not work, let me know.

Posting Permissions

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