Results 1 to 11 of 11
  1. #1
    Wind Dancer is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Location
    Wisconsin
    Posts
    5

    Replacing date field after updating different field

    I can't seem to get my date field to update to today when I add information to another field.



    My table has a lookup field, date field, text field, text field, text field.

    I have set the date field to default to today for each new record.

    I work with this table as a subform.

    I would like to have the date field update to the date I go back to the record and update the first text field.

    I have tried using after update, and an if - then statement, but nothing seems to work.

    If someone could help that would be great.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Show the code you attempted. Why doesn't it work, what happens - error message, wrong results, nothing?
    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
    Wind Dancer is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Location
    Wisconsin
    Posts
    5
    This is my last attempt

    Private Sub Date_Paid_AfterUpdate()

    If [Check_No] > 0 Then
    [Date_Paid] = Now()
    Else
    If [Check_No] < 0 Then
    [Date_Paid] = [Date_Paid]
    End If
    End Sub

    and nothing happens

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What does this mean - exactly
    My table has a lookup field, date field, text field, text field, text field.
    If you have a lookup field in a table definition, I suggest you remove it. Make a separate Lookup table.

    It isn't clear what this does.

    Code:
    Private Sub Date_Paid_AfterUpdate()
    
     If [Check_No] > 0 Then  'if greater than 0
           [Date_Paid] = Now()
         Else
     If [Check_No] < 0 Then    'if less than 0
           [Date_Paid] = [Date_Paid]
         End If
    End Sub
    
    and nothing happens
    What do you expect to happen?
    What if the check_no equals 0?

    I'm not sure I understand the reason for the ElseIF.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Shouldn't that be in the AfterUpdate event of Check_No?

    How could a check number ever be less than 0? Don't allow that.

    What should happen if check number is exactly 0?

    Have you run Debug > Compile? That code is missing an End If line.

    The Else and second If structure is not necessary.
    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.

  6. #6
    Wind Dancer is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Location
    Wisconsin
    Posts
    5
    So you only need to tell it what to do if there is a check no in that field?
    I was think like excel where you need both if true and false
    I don't want the date changed until there is a check no filled in.
    The check no field is text, is that the problem?
    I will try it with out the else, and put it in the check no after update and see what happens.

  7. #7
    Wind Dancer is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Location
    Wisconsin
    Posts
    5
    I thought I had the solution, but now I am getting a runtime error 3163 when it tries to update the date.
    Is there a way to make sure it is only using a short date?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    [Date_Paid] = Date()

    But that probably won't change the error.

    What is the exact message of the error?
    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.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What is the data type of Date_Field? Is it Date data type?

    As for the IF you could try this sort of thing:

    Private Sub Date_Paid_AfterUpdate()

    If CDbl([Check_No]) > 0 Then 'if greater than 0
    [Date_Paid] = Now()
    Else
    [Date_Paid] = [Date_Paid]
    End If
    End Sub

  10. #10
    Wind Dancer is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Location
    Wisconsin
    Posts
    5
    The field is too small to accept the amount of data you attempted to add
    Try inserting or pasting less data

    Just tried the last suggestion and that did it.

    thanks to everyone who helped!!!

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    The field is a text data type? Make it a date/time type.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-18-2013, 01:15 PM
  2. Replies: 3
    Last Post: 07-18-2013, 04:21 AM
  3. Updating one date field based on another
    By barryg80 in forum Forms
    Replies: 4
    Last Post: 04-19-2013, 03:17 AM
  4. Replies: 6
    Last Post: 12-11-2012, 09:40 PM
  5. Updating date field in access from excel causes error
    By madamson86 in forum Programming
    Replies: 2
    Last Post: 12-14-2011, 02:38 AM

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