Results 1 to 5 of 5
  1. #1
    Awesome! is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2014
    Posts
    10

    How to Update a Field using DateAdd and IIF in a form

    Hi All,I'm new to ACCESS and to this forum. Please let me know if this thread should go in a different place or any other rules of etiquette.

    I have a field in a form which indicates which date the person was last contacted [LastContact_Date] and I have a second field which states if the person is either ACTIVE or INACTIVE [ActiveInactive]. You would become inactive if the last time you were contacted was greater that 6 months ago.

    I built an update query which works. It has the following IIf statement

    IIf(DateAdd("m",6,[tblMAIN]![LastContact_Date])>Now(),"ACTIVE","INACTIVE")

    It would be good if the [ActiveInactive] field would update when you tab past the [LastContact_Date] field but not essential.

    Which is the best way to update a form field based on another form field? Do I use this update query in the [LastContact_Date] field or the [ActiveInactive] field in the form or table? Is there a better way than an update query to do the same thing?I am also new to VBA but I can copy and paste well enough if needed.

    Thanks in advance,



    Awesome!
    Last edited by Awesome!; 12-13-2014 at 02:36 AM. Reason: fixing formatting

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Saving calculated data (data dependent on other data) is often a bad idea. The Active/Inactive value can be calculated when needed.
    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
    Awesome! is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2014
    Posts
    10
    Thanks June7. Good advice. You are right that I don't need this calculated data saved.

    But how do I get this data to be visible in the form even if it not saved?

    Thanks,

    Awesome!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Options:

    1. create field with the expression in a query and use query as form RecordSource and bind textbox to the constructed field

    2. put expression in ControlSource property of textbox
    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.

  5. #5
    Awesome! is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2014
    Posts
    10
    Thanks,

    I tried the second option and I am getting a #name? error.

    ...but your statement about putting calculated fields in an form is a solid piece of advice.

    I think I will change my strategy and put a this calculated field in a report that only outputs the inactive people. I think this is more of what I am looking for.

    So I will make an attempt at creating this report and post to a new thread in the reports section if I have any questions.

    Any links to a tutorial about adding expressions to a report would be appreciated.

    Thanks!

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

Similar Threads

  1. Update Field based on form value
    By Auto in forum Forms
    Replies: 4
    Last Post: 11-20-2013, 11:57 AM
  2. Replies: 6
    Last Post: 04-26-2013, 10:07 AM
  3. Replies: 3
    Last Post: 09-20-2012, 11:23 AM
  4. Replies: 2
    Last Post: 07-16-2011, 07:56 PM
  5. Form using VBA to update field on table
    By comicwizard in forum Programming
    Replies: 3
    Last Post: 04-05-2011, 11:17 AM

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