Results 1 to 10 of 10
  1. #1
    bill s is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2015
    Posts
    8

    combo box not returning values when using wildcard

    I have pounded my head against something that should be simple. In my combo box where I am returning a row source using the query builder, I have the code below. In this case, IF the txtEmpRole is "OOEUSER", it returns records as expected. However if the txtEmpRole is not OOEUSER, then I get nothing despite the wildcard. Please tell me what I am doing wrong. Thank you!

    IIf(([Forms]![OoeEntryForm]![txtEmpRole])="OOEUSER",([Forms]![OoeEntryForm]![txtEmpId]),([CROSSWALK].[EMPID]) Like "*")





    Attached Thumbnails Attached Thumbnails ACCESS_BUILDER.jpg  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    Dynamic operators (=, <>, LIKE) will not work. The operator must be fixed. And including the field in the expression is definitely bad syntax.

    Why not just use the LIKE and wildcard?

    LIKE Forms!OoeEntryForm!txtEmpRole & "*"
    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
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Also, is EMPID defined as a Text Field or as a Number Field? IIRC, the Like operator can only be used against a Text Field...not against a Numerical Field.

    Linq ;0)>

  4. #4
    bill s is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2015
    Posts
    8
    Thank you for replying.

    I have a login. The login form passes the txtEmpRole and the txtEmpId.
    If the user roll is "ooeuser", I then want empid = their txtEmpID (which only show the users their own transactions)
    However, if the userroll is not "ooeuser", then it would be a manager (ooemgr) and I want to show all transactions.

    the first part of the if statement works fine (IIf(([Forms]![OoeEntryForm]![txtEmpRole])="OOEUSER",([Forms]![OoeEntryForm]![txtEmpId]),

    But I cannot get the "else" part of this to work. If I put a value such as 2 (2 being an empID), it will work (2 is not what I want to show but I tested to make sure something would return) . If I put >0, it doesn't work, nor does *.

    This below will not return any records. (note that empid is a numeric field)
    IIf(([Forms]![OoeEntryForm]![txtEmpRole])="OOEUSER",([Forms]![OoeEntryForm]![txtEmpId]),"*")


    Overall , I am simply trying to filter what the user sees based on their role. If they are a user, then they only see their own. If they are a manager, then they see all users.

  5. #5
    bill s is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2015
    Posts
    8
    and yes, it's numeric

    This returns value if txtEmpRole is OOEUSER
    IIf(([Forms]![OoeEntryForm]![txtEmpRole])="OOEUSER",([Forms]![OoeEntryForm]![txtEmpId]),([CROSSWALK].[EMPID]) Like "*")

    This returns value if txtEmpRole is not OOEUSER but it returns only userID = 2
    IIf(([Forms]![OoeEntryForm]![txtEmpRole])="OOEUSER",([Forms]![OoeEntryForm]![txtEmpId]),2)

    How can I return ALL UserIDs verus just user 2 in this example? I would think replacing the 2 with a * would work, but I get nothing returned.

    I am ready to change careers... :/




  6. #6
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Quote Originally Posted by bill s View Post
    I have pounded my head against something that should be simple. In my combo box where I am returning a row source using the query builder, I have the code below. In this case, IF the txtEmpRole is "OOEUSER", it returns records as expected. However if the txtEmpRole is not OOEUSER, then I get nothing despite the wildcard. Please tell me what I am doing wrong. Thank you!

    IIf(([Forms]![OoeEntryForm]![txtEmpRole])="OOEUSER",([Forms]![OoeEntryForm]![txtEmpId]),([CROSSWALK].[EMPID]) Like "*")



    Try adjusting your criteria to

    Code:
    LIKE IIf(([Forms]![OoeEntryForm]![txtEmpRole])="OOEUSER",([Forms]![OoeEntryForm]![txtEmpId]),"*")

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,633
    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.

  8. #8
    bill s is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Aug 2015
    Posts
    8
    that gives me an error "expression is incorrectly or too complicated to be evaluated."

  9. #9
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Bill, that's an indication of string vs numeric comparison. I see in other posts that you have numeric field, so you can't use a like-string comparison. You will need to adjust course choose one method, such as June's reference.

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Bill,
    Perhaps, if readers had some business context - a description in plain English about what you are trying to do - they could provide more focused responses and even suggest a few alternatives.

    I understand this situation
    I have pounded my head against something that should be simple.
    but would like to hear more of the issue/problem in business terms.

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

Similar Threads

  1. Replies: 1
    Last Post: 04-15-2015, 10:52 AM
  2. Replies: 2
    Last Post: 02-26-2015, 03:20 PM
  3. Query not returning all values
    By whitelexi in forum Queries
    Replies: 12
    Last Post: 09-06-2014, 11:40 PM
  4. Replies: 9
    Last Post: 12-05-2013, 11:48 AM
  5. Query not returning null values
    By janelgirl in forum Access
    Replies: 5
    Last Post: 10-11-2011, 10:31 AM

Tags for this Thread

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