Results 1 to 6 of 6
  1. #1
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31

    Filtering with a Textbox Breaks with Blank Entries

    I currently have a listbox that displays all the items in a table. It includes a couple queries to other tables as well; it works fine. The SQL is:

    Code:
    SELECT Items.ID, Items.QBItemNumber, MFGList.MFG, Items.Model, Items.ModelNumber, Items.HasUniqueID, Items.IsPhysical, Categories.Category, Categories.SubCategory
    FROM MFGList INNER JOIN (Categories INNER JOIN Items ON Categories.ID = Items.Category) ON MFGList.ID = Items.Manufacturer;
    I would like a listbox that displays all the items in a table... filtered against some text boxes and comboboxes.

    The problem is that when I add criteria (for example, I add the criteria "txtFilterItemNumber.Value" to the Items.ID field), the listbox is empty if the filter is blank. I really only want the filter applied if it has something in it.

    So then I tried
    added an "OR" statement. Here's the SQL for just one field:

    Code:
    SELECT Items.ID
    FROM Items
    WHERE ID=[txtFilterItemNumber].[Value] OR [txtFilterItemNumber].[Value]="";

    Still doesn't work--AND when I apply it all the fields, a million criteria appear in design view and Access crashes.

    I assume this has done before; what am I doing wrong?

    Dan

  2. #2
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    Update:

    I also tried a variation:

    Code:
    SELECT Items.ID
    FROM Items
    WHERE ID=[txtFilterItemNumber].[Value] OR [txtFilterItemNumber].[Value]="" OR IsNull([txtFilterItemNumber].[Value]);
    This works just fine to display all the records, but now the filter itself isn't working.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try something like:
    WHERE ID=[txtFilterItemNumber].[Value] OR ID = [txtFilterItemNumber].[Value]="";
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    I tried this but it just said " ' is not a valid name." I also didn't really follow your logic... it seems like you're doing multiple equivalence?

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    WHERE ID=[txtFilterItemNumber].[Value] OR ID = [txtFilterItemNumber].[Value] Is Null;
    and also
    WHERE ID=[txtFilterItemNumber] OR ID = [txtFilterItemNumber] Is Null;
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    dipique is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    31
    Turns out the error I encountered was actually from a different issue. Apparently a line break refused to leave the "Row Source" property of my component and that was causing the weird error.

    So I tried your suggestion and it worked, but I would love an explanation since I really have no idea what I'm saying. I think it's:
    WHERE (ID= txtFilterItemNumber.Value) OR ((ID = [txtFilterItemNumber].[Value]) Is Null));

    Is that correct?

    In any case, here's my final SQL that worked:

    Code:
    SELECT Items.ID, Items.QBItemNumber, MFGList.MFG, Items.Model, Items.ModelNumber, Items.HasUniqueID, Items.IsPhysical, Categories.Category, 
    Categories.SubCategory
    FROM MFGList INNER JOIN (Categories INNER JOIN Items ON Categories.ID = Items.Category) ON MFGList.ID = Items.Manufacturer
    WHERE 
    (Items.ID=txtFilterItemNumber.Value OR Items.ID=txtFilterItemNumber.Value IS NULL) AND 
    (Items.QBItemNumber=txtFilterQB.Value OR Items.QBItemNumber=txtFilterQB.Value IS NULL) AND 
    (MFGList.MFG=cboFilterMFG.Value OR MFGList.MFG=cboFilterMFG.Value IS NULL) AND 
    (Items.Model=txtFilterModel.Value OR Items.Model=txtFilterModel.Value IS NULL) AND 
    (Items.ModelNumber=txtFilterModelNumber.Value OR Items.ModelNumber=txtFilterModelNumber.Value IS NULL) AND 
    (Items.HasUniqueID=chkFilterUnique.Value OR Items.HasUniqueID=chkFilterUnique.Value IS NULL) AND 
    (Items.IsPhysical=chkFilterPhysical.Value OR Items.IsPhysical=chkFilterPhysical.Value IS NULL) AND 
    (Categories.Category=cboFilterCat.Value OR Categories.Category=cboFilterCat.Value IS NULL) AND 
    (Categories.SubCategory=cboFilterSubCat.Value OR Categories.SubCategory=cboFilterSubCat.Value IS NULL);
    This SQL, incidentally, makes Access go nuts. This is how Access treats it:

    Access Is Crazy.zip

    When I view the SQL, the processor spikes and Access sits frozen for a solid five minutes. If anybody knows how to talk Access into accepting more easily, I'd appreciate it. Anyways, hopefully this helps somebody out someday. Thanks for your help!

    Dan

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

Similar Threads

  1. Replies: 3
    Last Post: 01-04-2012, 11:14 AM
  2. Query to show blank entries
    By jo15765 in forum Queries
    Replies: 1
    Last Post: 12-09-2010, 08:15 AM
  3. Filling in blank textbox on a report.
    By cowboy in forum Reports
    Replies: 3
    Last Post: 04-16-2010, 02:50 PM
  4. Blank spaces at start of entries
    By rcmglover in forum Access
    Replies: 2
    Last Post: 03-26-2010, 10:42 PM
  5. Column Breaks
    By Pam Buckner in forum Reports
    Replies: 0
    Last Post: 03-08-2010, 02:34 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