Results 1 to 11 of 11
  1. #1
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19

    Unhappy How to get rows with empty fields as well?


    Hey ppl,

    I have a table with several fields: ID, firstname, lastname1 and lastname2. When I set the criteria for lastname2 to "*" I only get the rows that actually have a second lastname added. If I don't state any criteria there I get the ones with only the first lastname as well. Why is that?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about posting the SQL of the query you have?

  3. #3
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    Try changing the criteria from "*" to
    Is Null or Like "*"

  4. #4
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    Quote Originally Posted by CraigDolphin View Post
    Try changing the criteria from "*" to
    Is Null or Like "*"
    When I type in "*" the "Like" is added automatically. Can I do something like Is Null OR Like "*"?

  5. #5
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    It works!

    Like "*"+get_global("V_lastname2")+"*" Or Is Null

  6. #6
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    Damn...I just realized that I always get the ones with empty fields now (not very surprising). There's a field called "country" as well and if I search for, say, Denmark, I also get those people whose country of origin is unknown.

    So the desired behaviour is different depending on what the user thinks is the most important parameter. This is getting complicated...

  7. #7
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    Life is complicated

    You could use another criterion (Is Null) in the country field that excludes records with a null value in that field.

  8. #8
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    Quote Originally Posted by CraigDolphin View Post
    Life is complicated

    You could use another criterion (Is Null) in the country field that excludes records with a null value in that field.
    But that would exclude those at all times. If I search for "Hansen" from "Denmark" (with "OR Is Null" added) I get both that person as well as all those immigrants whose lastname field is blank.

  9. #9
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    I think I solved it..! If a text field is empty the corresponding variable is set to "* Or Is Null", otherwise it's txtField + "*". Phew, that was easier than I thought.

  10. #10
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    Or maybe not... That doesn't work if you try to pass it on as a string, since...well, since it's a text string and not a command. Hmm, is it possible to make commands variable?

  11. #11
    Orabidoo is offline Novice
    Windows 7 Access 2007
    Join Date
    Apr 2009
    Posts
    19
    Maybe I should build the whole SQL string in VBA code and pass it directly to the list box?

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

Similar Threads

  1. Combining columns into rows
    By steeveepee33 in forum Queries
    Replies: 5
    Last Post: 04-30-2009, 09:18 PM
  2. Access 2003 returns empty recordset
    By Leelers in forum Queries
    Replies: 0
    Last Post: 03-20-2009, 11:11 AM
  3. Counting rows
    By anishap in forum Access
    Replies: 0
    Last Post: 10-08-2008, 10:41 PM
  4. Replies: 1
    Last Post: 07-14-2008, 12:15 PM
  5. Queries the max from two rows
    By mohsin74 in forum Queries
    Replies: 0
    Last Post: 12-15-2006, 12:52 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