Results 1 to 5 of 5
  1. #1
    mavisyew is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    34

    Search by one field or more field

    Hi All,

    I have a form to allow the user to search by paratmeter.

    1. Date
    2. Status
    3. Type

    My question will be, the user can enter either one field to search for the list of information or enter the 3 fields and those which totally match the 3 field will show.

    For example in my table:

    Date Status Type
    29/08/2014 Pending Toilet
    01/10/2014 New Toilet
    08/08/2014 resolved Carpark
    29/08/2014 Pending Door

    If the user search for Status = Pending only then it will show:

    29/08/2014 Pending Toilet
    29/08/2014 Pending Door




    If the user Search by Type = Toilet, and Status = New then it will show:
    01/10/2014 New Toilet

    If the user Search by Date = 29/08/2014, Type = Toilet, and Status = Pending then it will show:

    Date Status Type
    29/08/2014 Pending Toilet

    How can i write the query?

    I wrote something below but dont not work.
    It show me all the data.

    SELECT TBLCaseDetail.Status, TBLCaseDetail.ReportedDate, TBLCaseDetail.Type
    FROM TBLCaseDetail
    WHERE (((TBLCaseDetail.Status)=Forms!FormFindCase!Status Selection) Or ((TBLCaseDetail.ReportedDate)=Forms!FormFindCase!D ateSelection) Or ((TBLCaseDetail.Type)=Forms!FormFindCase!CaseTypeS election)) or (((TBLCaseDetail.Status)=Forms!FormFindCase!Status Selection) And ((TBLCaseDetail.ReportedDate)=Forms!FormFindCase!D ateSelection)) ;


    Thanks for helping

  2. #2
    mavisyew is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    34
    If the user enter only one field it will search using that field only.
    If the user enter all the 3 fields or only 2 fields, then it will use the field which enter to search for the case list.

    Thanks

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I use VBA to create an SQL string. Then, the SQL string will be used to query the tables. There are various approaches to this. But, building the string using VBA behind a form is the key point.
    http://www.baldyweb.com/BuildSQL.htm

    http://allenbrowne.com/ser-62code.html

  4. #4
    mavisyew is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Aug 2014
    Posts
    34
    Hi ItsMe,

    Thanks for your reply.
    Have read your code.
    Not really understand as i am quite new to access.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Here's a free video tutorial showing a simple Search form. It's in Access 2000/2003 but the concept/content is key to your issue.

    Here is a link from Allen Browne that applies to your situation.
    Good luck

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 09-02-2013, 04:33 PM
  2. Replies: 3
    Last Post: 08-22-2012, 03:28 AM
  3. Replies: 7
    Last Post: 08-08-2012, 03:28 PM
  4. Replies: 3
    Last Post: 08-26-2011, 12:11 PM
  5. Replies: 2
    Last Post: 08-31-2010, 08:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums