Results 1 to 6 of 6
  1. #1
    acm007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    12

    Question Use checkbox to filter data


    Hi, please see picture below:

    Click image for larger version. 

Name:	0003.jpg 
Views:	14 
Size:	68.6 KB 
ID:	34429

    I want to write a VBA code so I when the checkbox or button (both at the top of the screen) is checked, it does not show the items that are "Canceled" or "Received" in the Status column.

    Items names:
    1) status search box is called "S_Status"
    2) status dropdown menu is called "Status"
    3) the dropdown option is pulled from Query "N_Q_PlacingOrders_Status" which pulls from Table "N_T_Placing Orders_Status".

    I am not too experienced with VBA, so if you can please help me write this code, I would really appreciate!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    With multiple optional criteria, I tend to use dynamic SQL, as demonstrated in the sample db here:

    http://www.baldyweb.com/BuildSQL.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    acm007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    12
    Hi,

    I tried to understand it from your website, however since my knowledge is very limited I was unable to do it. I tried the following but is still not working correctly. Would you be able to help me fix it?

    Private Sub CheckBox_Click()
    If CheckBox = True Then
    DoCmd.ApplyFilter , Status = True
    If CheckBox = False Then
    Exit Sub
    End If
    End If
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try
    Code:
    If Me.CheckBoxName = True Then
      Me.Filter = "Status = True"
      Me.FilterOn = True
    Else
      Me.Filter = ""
      Me.FilterOn = False
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    I thought you said you wanted to filter out Canceled and Received:
    Code:
    If Me.CheckBoxName = True Then
      Me.Filter = "Status <> 'Canceled' AND Status <>'Received'"
      Me.FilterOn = True
    Else
      Me.Filter = ""
      Me.FilterOn = False
    End If
    Cheers,
    Vlad

  6. #6
    acm007 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    12
    Thank you Pbaldy and Gicu! Yes Gicu, excluding those two options worked really well. Thank you again!

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

Similar Threads

  1. How to filter cbobox based on checkbox
    By MdHaziq in forum Programming
    Replies: 5
    Last Post: 12-26-2017, 09:39 PM
  2. Checkbox filter
    By cbende2 in forum Access
    Replies: 2
    Last Post: 05-27-2015, 07:20 AM
  3. Filter checkbox upon opening form
    By vickster3659 in forum Programming
    Replies: 9
    Last Post: 11-06-2014, 10:58 AM
  4. Checkbox Filter?
    By 82280zx in forum Forms
    Replies: 7
    Last Post: 03-14-2014, 10:35 AM
  5. Checkbox filter on a form
    By aletrindade in forum Access
    Replies: 1
    Last Post: 12-02-2009, 06:22 AM

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