Results 1 to 8 of 8
  1. #1
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91

    Data not displaying when setting Criteria for Field in a Query

    When I set a criteria to filter data base on a combo box, it is causing all my data to be hidden until I make a selection. For example, I want all data to be displayed, by not applying any selection from the combo. I click submit and it causes my list box to display nothing. What would cause this?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You want a listbox to be conditional on combobox selection?

    What is the listbox RowSource?

    What is the VBA procedure code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    Quote Originally Posted by ryder214 View Post
    When I set a criteria to filter data base on a combo box, it is causing all my data to be hidden until I make a selection. For example, I want all data to be displayed, by not applying any selection from the combo. I click submit and it causes my list box to display nothing. What would cause this?
    The RowSource for the ListBox is qSciName, and located on a Form called 003_Species. The combo boxes is on Form 2 aka 002_Criteria with a row source called qSpeciesType, the names are cboTypeOne, cboTypeTwo, cboTypeThree, cboTypeFour, and cboTypeFive.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Too complicated for me to follow. I would have to examine db and debug code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    this works for me everytime...
    use a continuous form to show all records,
    then when the user fills in the boxes, then clicks the FIND button, use vb to build the where clause:
    Code:
    sub btnFind_click()
    dim sWhere as string
    sWhere = "1=1"
    if not IsNull(txtBox1) then sWhere = sWhere & " and [field1]='" & me.txtBox1 & "'"
    if not IsNull(txtBox2) then sWhere = sWhere & " and [field2]='" & me.txtBox2 & "'"
    if not IsNull(txtBox3) then sWhere = sWhere & " and [field3]='" & me.txtBox3 & "'"
    if sWhere = "1=1" then
       me.filterOn = false
    else
       me.filter = sWhere
       me.filterOn = true
    endif

  6. #6
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    deleted *Not explained clear*

  7. #7
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    I received the following message Syntax error (missing operator) in query expression ' AND Criteria.Type='Example One'"

    Code:
         '----------------------------------
         'COMBOBOX FILTERING:
         strFilterString3 = ""
         If Not IsNull(TypeONE) Then strFilterString3 = strFilterString3 & " AND Criteria.Type='" & Me.TypeONE & "'"
         If strFilterString3 = "1=1" Then
            Me.FilterOn = False
         Else
            Me.Filter = strFilterString3
            Me.FilterOn = True
         End If

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The AND causes the error, since there's nothing previous to it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Setting Query Criteria using Iif Statement
    By thexxvi in forum Access
    Replies: 7
    Last Post: 12-14-2015, 01:27 PM
  2. Replies: 2
    Last Post: 11-03-2015, 08:56 AM
  3. Replies: 2
    Last Post: 10-19-2012, 01:44 AM
  4. Setting Criteria with a Lookup Field
    By winteram in forum Queries
    Replies: 1
    Last Post: 08-16-2011, 09:44 AM
  5. Setting criteria in a calculated date field
    By SteveReberger in forum Access
    Replies: 0
    Last Post: 10-29-2008, 06:58 AM

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