Results 1 to 15 of 15
  1. #1
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8

    Query with Blanks and Non-Blanks

    Hi there,

    Crash coursing in Access here and trying to learn on my own. I've got a majority of the basics down and have started building a query to populate in a list box below it. I have built a search form that allows the user to search based on a number of criteria, but not have to populate all of the fields to get results.

    I can get the criterias to reflect correctly as long as all criteria are populated, but now I've gotten to field where there are some values that are blank and now I seem to be stuck.

    The formula I was using for the first fields was: Like "*" & [Forms]![Comic Search]![ComicTitle] & "*"

    When I try to add the same formula in the search query for the field containing blank values, it only shows data that contains values in the comments fields. If I add an or "Is Null" statement, then I get all data and the comments field doesn't filter based on the search criteria.



    Any help would be most appreciated as I've been stuck on this one issue for almost 3 days now.

    I have attached pics of the DB here.

    Click image for larger version. 

Name:	Comic List.jpg 
Views:	23 
Size:	221.1 KB 
ID:	20784 Click image for larger version. 

Name:	Comic Query.jpg 
Views:	24 
Size:	81.5 KB 
ID:	20785 Click image for larger version. 

Name:	Search Form.jpg 
Views:	24 
Size:	162.1 KB 
ID:	20786

    Thanks in advance.

  2. #2
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2003
    Join Date
    Sep 2013
    Posts
    287
    Like [Forms]![Comic Search]![Comments] & "*"

    Ditch that first asterisk. Should work for ya.

    Edit: Nevermind, that won't accomplish what you want. I do that with my "Store #" field, but you need to be able to type anything in, as opposed to knowing what it starts with. Ignore me. My bad.

  3. #3
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8
    Ok, well then, anyone else?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    The Or Is Null should work.

    Like "*" & [Forms]![Comic Search]![Comments] & "*" Or Is Null

    Assumes blanks are actually nulls and not empty strings. I don't allow empty strings in text fields.

    Is Comments a text or memo field (short text or long text)?
    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
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8
    It's a memo field. I tried it with the Or Is Null and it wouldn't give me the limited results if I had a criteria in the Comments field. It still showed all the blanks as well due to the Or Is Null option.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    I misunderstood.

    I think you need to handle the nulls by calculating a field to replace with empty string. Use Nz([Comments],"") and then apply filter criteria to that constructed field.

    I NEVER use dynamic parameterized queries. I prefer http://www.allenbrowne.com/ser-62.html
    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.

  7. #7
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8
    June7, I changed it to a short text field, but it still didn't make a difference.

    Ah, you updated your post.

    Remember. crash coursing in Access. All I read when I read this:
    I think you need to handle the nulls by calculating a field to replace with empty string. Use Nz([Comments],"") and then apply filter criteria to that constructed field.
    is like the teacher from Charlie Brown. Can you explain in stupid people's terms?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    Try something like:

    SELECT * FROM [Comic Books] WHERE Nz([Comments],"") Like [Forms]![Comic Search]![Comments] & "*";
    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.

  9. #9
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8
    Ok, tried that and I got the error:

    The syntax of the subquery in this expression is incorrect. Check the subquery's syntax and enclose the subquery in parentheses.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    There is no subquery in my example. Post your attempted exact full SQL statement.
    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.

  11. #11
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8
    Oh, I didn't do anything in SQL. I don't even know how to do that. Every time I've seen instructions saying to do something in SQL, I try to figure something else out as I have no idea where to start to learn that. I'm beginning to think this is above my abilities.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    Then you didn't try what I suggested. What did you try?

    SQL is built by the Query Builder. Open query builder, build query in the designer, switch to SQL View to see the statement. This is basic Access functionality.

    Can copy/paste the suggested SQL into SQL View.
    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.

  13. #13
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8
    Still getting an error, but here is the SQL coding:

    Code:
    SELECT [Comic Books].[Comic Book Title], [Comic Books].[Comic Book Issue #], [Comic Books].Grade, [Comic Books].Copies, [Comic Books].[Storage Location], [Comic Books].Comments, [Comic Books].Publisher
    FROM [Comic Books]
    WHERE ((([Comic Books].[Comic Book Title]) Like "*" & IIf(IsNull([Forms]![Comic Search].[ComicTitle])=False,[Forms]![Comic Search].[ComicTitle],"*") & "*") AND (([Comic Books].[Comic Book Issue #]) Like IIf(IsNull([Forms]![Comic Search].[ComicIssue])=False,[Forms]![Comic Search].[ComicIssue],"*")) AND (([Comic Books].Grade) Like "*" & IIf(IsNull([Forms]![Comic Search].[ComicGrade])=False,[Forms]![Comic Search].[ComicGrade],"*") & "*") AND (([Comic Books].Copies) Like IIf(IsNull([Forms]![Comic Search].[CopiesOwned])=False,[Forms]![Comic Search].[CopiesOwned],"*")) AND (([Comic Books].[Storage Location]) Like IIf(IsNull([Forms]![Comic Search].[StorageLoc])=False,[Forms]![Comic Search].[StorageLoc],"*")) AND (([Comic Books].Comments) SELECT * FROM [Comic Books] WHERE Nz([Comments],"") Like [Forms]![Comic Search]![Comments] & "*" AND (([Comic Books].Publisher) Like "*" & IIf(IsNull([Forms]![Comic Search].[Publisher])=False,[Forms]![Comic Search].[Publisher],"*") & "*"))
    ORDER BY [Comic Books].[Comic Book Title], [Comic Books].[Comic Book Issue #], [Comic Books].Grade;

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,965
    You have placed my suggested statement within another statement. Since what I offered was a complete SQL statement, your query is not what I intended. Paste it into the SQL View of a new blank query object. If you want to add more filter criteria do that in Design view. The IIf() is not needed because of the LIKE and wildcard structure. However, LIKE and wildcard is intended for use on text type fields. Does not work properly with number or date type. For instance, if Copies is a number field and the parameter is 7, will return records were values begin with 7, such as 7, 71, 72, 73, etc.

    SELECT [Comic Books].*
    FROM [Comic Books]
    WHERE [Comic Book Title] Like "*" & [Forms]![Comic Search].[ComicTitle] & "*" AND [Comic Book Issue #] Like [Forms]![Comic Search].[ComicIssue] & "*" AND Grade Like [Forms]![Comic Search].[ComicGrade] & "*" AND Copies Like [Forms]![Comic Search].[CopiesOwned] & "*" AND [Storage Location] Like [Forms]![Comic Search].[StorageLoc] & "*" AND Nz([Comments],"") Like [Forms]![Comic Search]![Comments] & "*" AND Publisher Like "*" & [Forms]![Comic Search].[Publisher] & "*"
    ORDER BY [Comic Book Title], [Comic Book Issue #], Grade;

    Review: http://datapigtechnologies.com/flash...tomfilter.html

    I NEVER use dynamic parameterized queries. Did you review the Allen Browne link posted earlier?
    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.

  15. #15
    getalinks is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    8
    That did it! Thank you for being so patient with me. I did check out the link, but it seemed way more than what I needed. I really appreciate all your help.

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

Similar Threads

  1. Replies: 7
    Last Post: 03-26-2014, 06:28 AM
  2. Sorting Blanks
    By WickidWe in forum Queries
    Replies: 1
    Last Post: 12-11-2013, 03:23 PM
  3. Too many blanks in Labels
    By george3095 in forum Access
    Replies: 4
    Last Post: 12-15-2012, 09:50 AM
  4. Replies: 6
    Last Post: 06-14-2012, 03:39 PM
  5. SQL Update with blanks
    By Tyork in forum Programming
    Replies: 1
    Last Post: 12-17-2010, 10:12 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