Results 1 to 8 of 8
  1. #1
    the problem is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    5

    Angry Trouble with Text field: IIF() & Dates

    I would like the IIF() statement to display Today's date if [StartDate]=[EndDate]. If not, I would like to display the phrase [StartDate] to [EndDate].



    However, it's not working and it reverts to the second code every time.



    Code:
    =IIf([Forms]![DateRange]![StartDate]=[Forms]![DateRange]![EndDate],"=Date()","="Forms![DateRange]![StartDate]" & "-" & "Forms![DateRange]![EndDate]"")
    .

    Code:
    =IIf([Forms]![DateRange]![StartDate]=[Forms]![DateRange]![EndDate],"=Date()","Forms![DateRange]![StartDate] -  Forms![DateRange]![EndDate] ")

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I'm not sure where you are trying to do this (it might make a difference), but if you want to display today's actual date (i.e. the value 7/25/2012), the IIF() would look like this

    IIF(forms!daterange!startdate=forms!daterange!endd ate, date(), .....)


    Let's assume that the values in startdate and enddate are 7/1/2012 and 7/31/2012 respectively; do you want the false part to display 7/1/2012 - 7/31/2012 or the text value: [StartDate] to [EndDate]

    If you want to see actual dates 7/1/2012 - 7/31/2012, the IIF() would look like this

    IIF(forms!daterange!startdate=forms!daterange!endd ate, date(), forms!daterange!startdate & "-" & forms!daterange!enddate)

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try this:
    Code:
    =IIf([Forms]![DateRange]![StartDate]=[Forms]![DateRange]![EndDate],Date(),Forms![DateRange]![StartDate] & " - " & Forms![DateRange]![EndDate])

    Edit: Dang my slow typing skills! Looks like you already have a reply that says pretty much the same thing as the formula I came up with!

  4. #4
    the problem is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    5
    WHAT WHAT!!!!!!!! SO AWESOME. Thanks guys you both are the best! Solved!!!!!!

    How do I change it to solved?

  5. #5
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome!

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your welcome also. Just remember - everything put between double-quotes is treated as literal text, so you do not want to put your variables between double-quotes if you are looking to return their value.

    As for marking a thread as "Solved", see here: https://www.accessforums.net/forum-s...lved-1828.html

  7. #7
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You know, I could not find anything in the FAQ on how to mark a thread as solved, but I think only the original poster can do that. I believe that there are some thread tools that you can use.

    Oops I see JoeM has provided a link

  8. #8
    the problem is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    5
    Thanks again! I appreciate the information on the double quotes.

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

Similar Threads

  1. Replies: 12
    Last Post: 06-04-2012, 10:55 AM
  2. more trouble with text fields as dates
    By mitchmcc in forum Queries
    Replies: 3
    Last Post: 03-14-2012, 08:51 AM
  3. Having trouble with moving text to table
    By geoffwbailey in forum Programming
    Replies: 3
    Last Post: 06-17-2010, 11:00 AM
  4. Replies: 2
    Last Post: 05-05-2010, 02:52 PM
  5. Having trouble with dates in my Data Base!!!!
    By BigPhil in forum Queries
    Replies: 4
    Last Post: 02-15-2006, 12:47 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