Results 1 to 9 of 9
  1. #1
    Theremin_Ohio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Location
    Chillicothe, OH
    Posts
    12

    Exclamation iif statement to generate date

    There are three fields in my customer database that should be taken into consideration for my iif statement:



    Fields:
    Contact_Date (date field)
    Contact_Type (look-up field)
    Next_Appointment (date field)

    How ought I to express "if Contact_Type=[Flag_Only], [Flag/Pole_Install] or [Scheduled_Maintenance], then [Next_Appointment]=[Contact_Date]+180 days"?


    I want to be able to send maintenance reminders to current customers.


    Cheers!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Where are you using this expression - in a query or textbox on form? Cannot set value of [Next_Appointment] within a query or textbox. Must use code (VBA or macro). However, really no need to save this calculated value. You can always calculate it when needed. A principle of relational database is to save raw data and do calcs in queries/reports.

    IIf([Contact_Type]="Flag_Only" Or [Contact_Type]="Flag/Pole_Install" Or [Contact_Type]="Scheduled_Maintenance", [Contact_Date]+180, Null)
    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
    Theremin_Ohio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Location
    Chillicothe, OH
    Posts
    12
    Quote Originally Posted by June7 View Post
    Where are you using this expression - in a query or textbox on form? Cannot set value of [Next_Appointment] within a query or textbox. Must use code (VBA or macro). However, really no need to save this calculated value. You can always calculate it when needed. A principle of relational database is to save raw data and do calcs in queries/reports.

    IIf([Contact_Type]="Flag_Only" Or [Contact_Type]="Flag/Pole_Install" Or [Contact_Type]="Scheduled_Maintenance", [Contact_Date]+180, Null)
    I am using this expression in a table that appears as a sub at the bottom of a form. I will need to know this date for potentially thousands of customers (right now, there are several hundred names in the database), but already it takes incredibly long to review each record and select the type of contact and/or next appointment date. I work in a fast-paced environment where I cannot afford to spend thirty to forty-five minutes inputting customer contact history.

    Is the VBA code simple to embed? I would be much happier with this option.

  4. #4
    Theremin_Ohio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Location
    Chillicothe, OH
    Posts
    12
    Also, I tried to enter the expression as a validation rule in design view, and a dialogue box popped up stating there is an invalid operand operator?

  5. #5
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    off the cuff - and assuming you didn't make a typo - to enter that phrase as a validation rule I think you need to tweak it:

    =(phrase)


    am pretty sure you have to wrap that phrase with the =( )

    if it were in a query you would need to preceed it with:
    FieldName: phrase

  6. #6
    Theremin_Ohio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Location
    Chillicothe, OH
    Posts
    12

    Red face

    Quote Originally Posted by NTC View Post
    off the cuff - and assuming you didn't make a typo - to enter that phrase as a validation rule I think you need to tweak it:

    =(phrase)


    am pretty sure you have to wrap that phrase with the =( )

    if it were in a query you would need to preceed it with:
    FieldName: phrase
    Do you mean I ought to write my validation rule as...

    "Next_Appointment"=(IIf([Contact_Type]="Flag_Only" Or [Contact_Type]="Flag/Pole_Install" Or [Contact_Type]="Scheduled_Maintenance", [Contact_Date]+180, Null))

    I am attempting to do a lot of new things at once! Thanks for your assistance.

  7. #7
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    =(phrase)

    just add those symbols in the appropriate place and see if it works....

  8. #8
    Theremin_Ohio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Location
    Chillicothe, OH
    Posts
    12
    Quote Originally Posted by NTC View Post
    =(phrase)

    just add those symbols in the appropriate place and see if it works....
    I am assuming that was a yes. Thank you very much! I'll try this tomorrow.

  9. #9
    Theremin_Ohio is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2011
    Location
    Chillicothe, OH
    Posts
    12
    Quote Originally Posted by NTC View Post
    =(phrase)

    just add those symbols in the appropriate place and see if it works....
    NTC,

    I tried wrapping this expression as you suggested (I copied and pasted to eliminate errors), by entering Field_Name=(expression), but I got an error message:

    "Invalid SQL syntax - cannot use multiple columns in a column-level CHECK constraint."

    I take it that this means, in plain English, that there was a problem with the manner in which the look-up field options are referenced in the expression, OR it means I have wrapped your expression incorrectly.

    I tried the following two variations which both yielded the same error message:

    "Next_Appointment"=(IIf([Contact_Type]="Flag_Only" Or [Contact_Type]="Flag/Pole_Install" Or [Contact_Type]="Scheduled_Maintenance", [Contact_Date]+180, Null))

    [Next_Appointment]=(IIf([Contact_Type]="Flag_Only" Or [Contact_Type]="Flag/Pole_Install" Or [Contact_Type]="Scheduled_Maintenance", [Contact_Date]+180, Null))

    Am I using incorrect brackets or parentheses to wrap certain portions of my expression? Any further assistance would be greatly appreciated.

    Theremin_Ohio

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

Similar Threads

  1. ISO8601 Date in a IIF Statement
    By monkeyman in forum Queries
    Replies: 2
    Last Post: 05-23-2011, 12:16 PM
  2. Date Field empty if statement
    By dubsdj in forum Programming
    Replies: 4
    Last Post: 03-06-2011, 04:02 PM
  3. generate next possible identifier
    By BayerMeister in forum Programming
    Replies: 5
    Last Post: 08-25-2010, 08:30 AM
  4. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  5. Generate Image
    By dbman in forum Import/Export Data
    Replies: 0
    Last Post: 01-31-2008, 10:46 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