Results 1 to 12 of 12
  1. #1
    mommyof4kids is offline Novice
    Windows XP Access 2002 (version 10.0)
    Join Date
    Mar 2012
    Posts
    20

    Need help with IIF statement

    I have a date of birth (DOB) for each person in my db. I need to calculate a mandatory retirement ages for some. I have created a Yes/No checkbox to indicate if they have a mandatory retirement date.

    To calculate the date I have DateAdd("yyy", 56, [DOB]) and that works great!

    I only want to show the mandatory retirement date if the checkbox is checked, otherwise it would be blank (or better yet, not shown at all)

    I think I need an IIF statement ?? IIF(([Checkbox]=-1, ???????

    Any help is greatly appreciated!!!

  2. #2
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Are you working in a query, a form or a report?

    Dale

  3. #3
    mommyof4kids is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    20

    IFF Statement

    I am working in a form

    Quote Originally Posted by rzw0wr View Post
    Are you working in a query, a form or a report?

    Dale

  4. #4
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Make a query for the form.
    SELECT Field1, Field2,.... FROM TableName WHERE MandatoryRetirementCheckbox = True;

    Dale

  5. #5
    mommyof4kids is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    20

    IFF Statement

    I need to show all records, not just those that have the checkbox marked

    Or how do I only show a mandatory retirement date if the checkbox is checked, otherwise show N/A ??


    Quote Originally Posted by rzw0wr View Post
    Make a query for the form.
    SELECT Field1, Field2,.... FROM TableName WHERE MandatoryRetirementCheckbox = True;

    Dale

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Quote Originally Posted by rzw0wr View Post
    Make a query for the form.
    SELECT Field1, Field2,.... FROM TableName WHERE MandatoryRetirementCheckbox = True;

    Dale
    That will make the records where MandatoryRetirementCheckbox = False unavailable.

    Perhaps it would be better to use some code, maybe:
    Code:
    If Me.[Checkbox]=True Then
    Me.[NameOfControlToHide].Visible=True
    Else
    Me.[NameOfControlToHide].Visible=False
    This would need to be in the forms On Current event and the After Update event of the checkbox.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Gotcha. Sorry misread your post.
    Is this a single form, a datasheet or a continuous form?

    Dale

  8. #8
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    If you want the field to be text, and display "N/A", then you could do this:

    IIF([Checkbox], Format (DateAdd("yyyy", 56, [DOB]), "MM/DD/YYYY") , "N/A")

    If you want the field to be a date field, you could do this:

    IIF([Checkbox], DateAdd("yyyy", 56, [DOB]), 0)

    and use conditional formatting to make 0 records show nothing when value is 0.
    Last edited by Dal Jeanis; 06-21-2013 at 08:10 AM. Reason: eliminate excess open parenthesis

  9. #9
    mommyof4kids is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    20

    IFF Statement

    I get an error message: "The expression you entered has a function containing the wrong number of arguments"


    Quote Originally Posted by Dal Jeanis View Post
    If you want the field to be text, and display "N/A", then you could do this:

    IIF(([Checkbox], Format (DateAdd("yyyy", 56, [DOB]), "MM/DD/YYYY") , "N/A")

    If you want the field to be a date field, you could do this:

    IIF(([Checkbox], DateAdd("yyyy", 56, [DOB]), 0)

    and use conditional formatting to make 0 records show nothing when value is 0.

  10. #10
    mommyof4kids is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    20

    IFF Statement

    I get an error message: "The expression you entered has a function containing the wrong number of arguments"


    Quote Originally Posted by Dal Jeanis View Post
    If you want the field to be text, and display "N/A", then you could do this:

    IIF(([Checkbox], Format (DateAdd("yyyy", 56, [DOB]), "MM/DD/YYYY") , "N/A")

    If you want the field to be a date field, you could do this:

    IIF(([Checkbox], DateAdd("yyyy", 56, [DOB]), 0)

    and use conditional formatting to make 0 records show nothing when value is 0.

  11. #11
    mommyof4kids is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2012
    Posts
    20

    IFF Statement

    I have a main form that is more of a summary sheet for each employee (select employee from drop down list, it displays all of their information on the screen). If they need t enter/change information for that employee, I have a button on each section to open a form. In this case, to open the retirement information form..

    We have some employees that have a mandatory retirement age of 56, others that do not. I added a checkbox to indicate if they are mandatory. In the query I have the date calculating for everyone to age 56. Maybe that is my error? I don't want the query to only show Age56 people because the form needs to show the same data for all employees. I would like the form to display the mandatory date only for those that have a mandatory retirement date (and I need to show the date for only those employees).

    The form opens as a split form with the datasheet displaying on the bottom (they want to see all retirement actions they have processed for this employee, both ways)

  12. #12
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Sorry. I just edited to remove one of the opening parenthesis. The terms should start with

    IIF([Checkbox],

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

Similar Threads

  1. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Iif statement help
    By Firefighter22 in forum Queries
    Replies: 7
    Last Post: 09-30-2011, 10:59 AM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. BETWEEN in a FROM Statement
    By Cyborg in forum Queries
    Replies: 6
    Last Post: 05-12-2011, 01:54 PM
  5. Need Help with SQL Statement
    By Hank44 in forum Programming
    Replies: 3
    Last Post: 11-08-2010, 05:49 PM

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