Results 1 to 9 of 9
  1. #1
    forthemame is offline Novice
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    5

    Question On Setting Up Simple "If" Logic For a Report

    Hello,


    I'm trying to setup a check box for an existing report. The report lists items from an inventory table. I'm trying to add a new column called "Computer" that will display a check box (or a YES flag or something) next to any item in the report if it is a computer.

    Computers are denoted in the data by the 'Code' field from the 'inven' table. If the Code is equal to 25, then the item is a computer.

    I figure the logic would be something similar to this: If ( Code = '25' ), Print ('Yes'), Else Print (' ')

    If there's a way to actually put a check in the text box, then that'd be great too. I suppose it's not mandatory, but nice to have.

    I played around with the expression builder, but I couldn't figure out how to do this seemingly simple add-on. I have the 'Computer' heading showing up fine, but the check box and associated logic is a bit harder. Any thoughts?

    Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try this as the control source of a checkbox in the report:

    =IIf(Code = '25', True, False)

    Drop the quotes around 25 if the Code field has a numeric data type.

  3. #3
    forthemame is offline Novice
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by pbaldy View Post
    Try this as the control source of a checkbox in the report:

    =IIf(Code = '25', True, False)

    Drop the quotes around 25 if the Code field has a numeric data type.
    Thanks for the reply. When I run the report, it prompts me for the Department (as expected) but it's also prompting me for the Code value. Even if I enter 25, it returns -1 in the Computer column for every item in the inventory.

    Any idea what's going on?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, "Code" would have to be your actual field name, and that field would need to be in the report's source table/query.

  5. #5
    forthemame is offline Novice
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by pbaldy View Post
    Well, "Code" would have to be your actual field name, and that field would need to be in the report's source table/query.
    How do you check the source of the Report? Sorry for the lame questions.
    Thanks.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The source of the report is the Record Source property of the report. It could be a table, a saved query, or SQL.

  7. #7
    forthemame is offline Novice
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by pbaldy View Post
    The source of the report is the Record Source property of the report. It could be a table, a saved query, or SQL.
    Ah ha! I found the source, added the 'Code' field, and added the following to the Control Source of the Code 'checkbox':
    =IIf([Code]='25',True,False)

    Now, it seems to be displaying 0 for False and -1 for True for each of the items. Is there any way I can change this to Y and N, or T and F, or something a little more useful?

    Thanks!

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It sounds like you used a textbox instead of a checkbox. A checkbox would either be checked or not. If you want to stick with the textbox:

    =IIf([Code]='25',"T","F")

    or whatever you want to display in place of the T and F.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    forthemame is offline Novice
    Windows 7 Access 2007
    Join Date
    Feb 2010
    Posts
    5
    Quote Originally Posted by pbaldy View Post
    It sounds like you used a textbox instead of a checkbox. A checkbox would either be checked or not. If you want to stick with the textbox:

    =IIf([Code]='25',"T","F")

    or whatever you want to display in place of the T and F.
    Ah, I probably did use a textbox as I just copied an existing box on the page. I'll go look up checkboxes and see if that works.

    Thanks!

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

Similar Threads

  1. Populating a "Text" field in a Report
    By two_smooth in forum Reports
    Replies: 20
    Last Post: 02-19-2010, 11:25 AM
  2. a simple "display date " query
    By Ushera in forum Queries
    Replies: 2
    Last Post: 07-31-2009, 06:49 AM
  3. Report "WHERE" clause not working
    By rsearing in forum Reports
    Replies: 4
    Last Post: 05-26-2009, 02:07 PM
  4. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM
  5. "Count" and "Countif" in Reports
    By JMantei in forum Reports
    Replies: 1
    Last Post: 06-20-2006, 02:20 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