Results 1 to 6 of 6
  1. #1
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305

    Add multiple items to search form?


    I've got a form that allows the user to input information to filter down a report. The DB is employee complaints so the field in the form lets the user put in an employee's name to filter down to complaint just from that one person.

    Below is my code. I was hoping there's a way to allow users to put 2 or more names in the field, and maybe seperate them by commas or semicolons. And then the report shows records for both the names.

    Any suggestions on how to code that?

    Code:
    If Not IsNull(frm!txtEmployeeName) Then        
    If strWhere <> "" Then
    strWhere = strWhere & " AND "
    End If
    strWhere = strWhere & "[EmployeeName] LIKE '*" & frm!txtEmployeeName & "*'"
    End If

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you need to use OR or IN

    but not clear if user is entering a partial name or a full name - provide some example data of what a user might input and what you expect to get returned

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    More info please.
    Can you give us a sample showing initial items and some additional item(s) with expected result?

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I would recommend a different approach that would make it a lot easier to code and more flexible: create a local table to list the employees names (or better their numeric unique ids) and a yes\no field named IncludeInReport or similar. Then create a simple datasheet form based on this table and use that to replace the textbox you currently use for user input (as a subform). Now the user can select multiple employees in the subform (use combo's to display the names but bind the ID field); finally add the table to the report's record source and join on the employee ID and use True in the criteria row for the IncludeInReport field.

    You could also use a multi-select listbox but those are harder to code as you would have to loop through the selected items and dynamically build the SQL statement for the report.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by CJ_London View Post
    you need to use OR or IN

    but not clear if user is entering a partial name or a full name - provide some example data of what a user might input and what you expect to get returned
    Ideally, partial names. I was hoping that I could input 'John; Matthew' and then all records with John or Matthew in the 'EmployeeName' field would populate

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    OK - brief answer so a brief response

    You've answered your own question - you need to use 'OR'

    name=like '*john*' OR name like '*matthew*'

    all you have to do is split the user input and create the string. To split, use the split function

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

Similar Threads

  1. Multiple Items Form grouped items
    By Tuckejam in forum Forms
    Replies: 2
    Last Post: 04-29-2020, 10:00 AM
  2. Multi search items in a form
    By philip1101 in forum Access
    Replies: 7
    Last Post: 08-25-2019, 01:20 PM
  3. Replies: 3
    Last Post: 09-12-2016, 11:49 AM
  4. Replies: 8
    Last Post: 09-02-2015, 03:00 PM
  5. multiple items form
    By eraengineer in forum Forms
    Replies: 1
    Last Post: 04-17-2013, 03:33 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