Results 1 to 6 of 6
  1. #1
    JackieEVSC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    70

    Formatting output in an iif statement

    I am attempting to pull in the value of a field. If the value is null, I want the result to be "n/a". If there is a value in that field (CopyBarcode), I want the last seven digits of that value to populate.




    This is the code I am trying:


    AssetNum: IIf(([Admin_Copy]![CopyBarcode])="", "n/a", "Right([Admin_Copy]![CopyBarcode],7)"


    When I enter this, I get an this error: "The expression you entered is missing closing parenthesis, bracket (]), or vertical bar(|).


    I have tried a variety of things to correct this, but I keep getting the same error, regardless of what I try. As usual, I'm sure this isn't a difficult thing to do, but I'm stuck!


    Thanks for any help you can give me.

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Remove the " before Right and at the end. Remove the set of () around barcode. Add a ) at the end.

  3. #3
    JackieEVSC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    70
    I tried to follow your advice, but I'm missing something.

    The following give me an error "The expression you entered contains invalid syntax":

    1 - AssetNum: IIf(([Admin_Copy]![CopyBarcode])="","n/a",Right[Admin_Copy]![CopyBarcode],7)
    2 - AssetNum: IIf(([Admin_Copy]![CopyBarcode])="","n/a",Right([Admin_Copy]![CopyBarcode]),7)
    3 - AssetNum: IIf([Admin_Copy]![CopyBarcode]="","n/a",Right[Admin_Copy]![CopyBarcode],7)
    4 - AssetNum: IIf([Admin_Copy]![CopyBarcode]="","n/a",Right[Admin_Copy]![CopyBarcode],7)

    The following doesn't give me an error, but the field is empty after the query runs:


    AssetNum: IIf(([Admin_Copy]![CopyBarcode])="", "n/a", Right([Admin_Copy]![CopyBarcode],7))

    What am I doing wrong?

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Be careful about testing for "" (empty string) in a form text box. An blank text box on a form rarely will contain an empty string - it is far more likely to be Null. You can test for both possibilities with:

    IIf(nz([Admin_Copy]![CopyBarcode],"") = "", "n/a", Right([Admin_Copy]![CopyBarcode],7))

    If [Admin_Copy]![CopyBarcode] is Null, the Nz returns an empty string, otherwise it returns the existing value in [Admin_Copy]![CopyBarcode] (which might be an empty string)

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The first 4 are wrong, no ending ). Remove those () around barcode.

    Barcode might also be null: IIf(IsNull([Admin_Copy]![CopyBarcode) OR [Admin_Copy]![CopyBarcode]="",

  6. #6
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    163
    I think it's probably:
    AssetNum: IIf(IsNull([Admin_Copy]![CopyBarcode]) OR [Admin_Copy]![CopyBarcode]="","n/a", Right([Admin_Copy]![CopyBarcode],7))

    Hope I'm right! Good luck!

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

Similar Threads

  1. Replies: 2
    Last Post: 11-12-2015, 10:46 AM
  2. Formatting of output tables to excel
    By hinkwale in forum Access
    Replies: 2
    Last Post: 01-26-2015, 06:41 PM
  3. Formatting of output to excel
    By hinkwale in forum Access
    Replies: 0
    Last Post: 01-23-2015, 12:13 PM
  4. Replies: 4
    Last Post: 04-23-2014, 04:35 PM
  5. Replies: 4
    Last Post: 12-30-2013, 05:51 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