Results 1 to 5 of 5
  1. #1
    kelkan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    26

    error handling for dateadd function to return to previous value

    I am tracking certifications by expiration date and class date in a form. I have it set up in vba for afterupdate action in the CLASSCOMPLETED field for the following:

    Dim STRDATE As String
    STRDATE = DateAdd("M", Me.FREQUENCY, Me.CLASSDATE)


    If CLASSCOMPLETED = "YES" Then
    EXPIRATIONDATE = STRDATE

    End If

    This works great, but if the user changes the CLASSCOMPLETED back to "NO" for some reason, I want the EXPIRATIONDATE to revert to the original date. I assume that I do that through error handling or Else If function but I do not know how to write it. Can anyone help?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    You mean if the user changes back to "NO" in the same session with the record? Because once the record and its edits are committed to table the old value is gone.

    Review http://msdn.microsoft.com/en-us/libr.../ff821779.aspx

    Try:

    If ClassCompleted = "Yes" Then
    ExpirationDate = strdate
    Else
    ExpirationDate.Undo
    End If

    ClassComplete is a text or Yes/No datatype?
    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
    kelkan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    26
    CLASSCOMPLETED is a text field. I tried Else EXPIRATIONDATE.Undo and got error message "method not found"

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As June7 said, this has to be done during a single entering/editing of the Record, because once the data is saved/committed there is no retrieving the old data.

    Is there any reason that you have to actually see the date change, at the time that 'Yes' is entered into ClassCompleted? If not, you could simply place your original code in the Form_BeforeUpdate event. You won't see the change when it's made (unless this is a Datasheet or Continuous View Form) but it will be there when you return to the Record, and the change will only be there if ClassCompleted = 'Yes' when the Record is saved.

    Linq ;0)>

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

Similar Threads

  1. Split Function Error Handling
    By nguyenak in forum Programming
    Replies: 12
    Last Post: 06-25-2012, 01:52 PM
  2. DateAdd function for workdays?
    By 10 Gauge in forum Programming
    Replies: 2
    Last Post: 04-06-2011, 09:20 AM
  3. DateAdd Function
    By Desstro in forum Programming
    Replies: 3
    Last Post: 04-03-2011, 01:45 PM
  4. Help Please - DateAdd Function
    By graviz in forum Queries
    Replies: 3
    Last Post: 03-02-2010, 02:34 PM
  5. Replies: 2
    Last Post: 11-02-2009, 10:14 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