Results 1 to 5 of 5
  1. #1
    skelsey is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    2

    Needing to search by checkbox and/or text box criteria


    I have 4 different checkboxes (BridgeCheck, LandscapeCheck, RoadCheck, TrafficEngCheck), along with a text box (txtSearch and a search button (goButton). I am wanting to be able to 1) check one of the checkboxes and click the search button or 2) check one of the checkboxes type text in the text box and click the search button and only get those matching records. I have been scratching my head on how to do this. I would appreciate any help. Thank you in advance.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Here is a link to an often referenced search by Allen Browne. You may get some ideas from the article.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Test all controls for a possible filter then build the where clause:
    Code:
    sub btnFind_click()
    sWhere = "1=1"
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if  chkContact then sWhere = sWhere & " and [Contact]=" & chkContact.value
    
     'then filer
    me.filter = sWhere
    me.filterOn = true
    end sub

  4. #4
    skelsey is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    2
    Quote Originally Posted by orange View Post
    Here is a link to an often referenced search by Allen Browne. You may get some ideas from the article.
    Thank you very much for this. It helped a lot.

  5. #5
    Bullschmidt's Avatar
    Bullschmidt is offline Freelance DB Developer
    Windows 10 Office 365
    Join Date
    Mar 2020
    Location
    USA
    Posts
    64
    if chkContact then sWhere = sWhere & " and [Contact]=" & chkContact.value
    Or perhaps if want to search for anything in the field instead of just an exact match:
    if chkContact then sWhere = sWhere & " and [Contact] like '*' & chkContact.value & '*'

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

Similar Threads

  1. Replies: 2
    Last Post: 01-28-2019, 06:32 AM
  2. Replies: 3
    Last Post: 09-12-2016, 11:49 AM
  3. Replies: 1
    Last Post: 03-26-2015, 11:08 AM
  4. Replies: 3
    Last Post: 01-04-2015, 06:09 PM
  5. using checkbox as iif criteria
    By TheShabz in forum Queries
    Replies: 3
    Last Post: 01-18-2011, 05:10 PM

Tags for this Thread

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