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

    Help with unbound listbox in filter form

    I'm using a form with an unbound listbox to let users filter down a report. The only field on the form is the listbox. If the user doesn't select anything from the list box but clicks the command to open the report, I want nothing to happen. I tried achieving that with this line of code:

    Code:
    If Me.listComplaintCategory.ListCount = 0 Then Exit Sub
    Not working though. The report still opens with every record. Any idea what I'm doing wrong? Let me know if the full code is needed or an example DB.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by templeowls View Post
    I'm using a form with an unbound listbox to let users filter down a report. The only field on the form is the listbox. If the user doesn't select anything from the list box but clicks the command to open the report, I want nothing to happen. I tried achieving that with this line of code:

    Code:
    If Me.listComplaintCategory.ListCount = 0 Then Exit Sub
    Not working though. The report still opens with every record. Any idea what I'm doing wrong? Let me know if the full code is needed or an example DB.
    Why bother with the button. Why not code the opening of the report from an event of the listbox.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by Bob Fitz View Post
    Why bother with the button. Why not code the opening of the report from an event of the listbox.
    Not sure what you mean. Could you expand?

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by templeowls View Post
    Not sure what you mean. Could you expand?
    No. I don't think my earlier thoughts were not good. Perhaps use something like:
    Code:
     
        If Nz(Me.ListboxName, 0) = 0 Then
            MsgBox "Nothing Selected"
        Else
            'Open Report
        End If
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    The Listbox.ListCount is not affected by user selection, use:
    Code:
    If Me.listComplaintCategory.ItemsSelected.Count = 0 Then Exit Sub
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    templeowls is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    305
    Quote Originally Posted by Gicu View Post
    The Listbox.ListCount is not affected by user selection, use:
    Code:
    If Me.listComplaintCategory.ItemsSelected.Count = 0 Then Exit Sub
    Cheers,
    That worked. Thanks so much!

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

Similar Threads

  1. Filter Form with unbound dropdown
    By samot79 in forum Forms
    Replies: 11
    Last Post: 06-09-2017, 01:40 PM
  2. Replies: 11
    Last Post: 08-10-2015, 06:27 PM
  3. Filter a form using a listbox
    By jrosen12 in forum Forms
    Replies: 3
    Last Post: 03-23-2015, 07:44 AM
  4. Replies: 5
    Last Post: 06-23-2014, 03:32 PM
  5. Unbound Combo Box to filter form
    By Firefighter22 in forum Forms
    Replies: 4
    Last Post: 08-31-2011, 03:39 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