Results 1 to 7 of 7
  1. #1
    Sienna is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    19

    Date field updated when box checked

    I want a CompletedDate field updated when I check the "Completed" check box on a form.

    This is the After Update Event Procedure:

    Code:
    Private Sub Completed_AfterUpdate()
    If Me.Completed = True Then
    Me.DateCompleted = Date
    End If
    End Sub
    The form is viewed as a datasheet and is used as a subform on another form. There is another date field that automatically fills in a date when each record is created. The problem is that the DateCompleted field/control is being updated with the same date as the first date field, instead of now's date. I have tried replacing "Date" in the above code with "Date()" and "Now" and "Now()".

    As I was typing this, it occurred to me that perhaps since the first date field (as is the control on the form) is called "Date", then perhaps that's why it is updating the "DateCompleted" field with the date from the Date field. So, I changed the name of both the control and the field. It is no longer updating with the date from the first date field--now, I get this error message:

    Run-time error '2465':


    Microsoft Access can't find the field 'Date' referred to in your expression.

    Help, please?

    ETA: For clarity, the first date field and control are called "DateCreated." The second one is called "DateCompleted."

  2. #2
    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,870
    You could try putting the code in the Before Update and see if it makes a difference.
    If it's on the subform, I think Me will refer to the subform.
    Me.DateCompleted may actually be Me.Parent.DateCompleted if DateCompleted is a field/control on the main form.

    Another thought is to trap the error and do a debug.print of some of the controls
    eg.
    Debug.print Me.Name;Me.parent.Name

    Good luck

  3. #3
    Sienna is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    19
    Tried to move the code to Before Update--it didn't work.

    All of the controls are on the subform. In fact, I've been opening the subform on its own when testing.

    How do I do a debug.print? Is that example a line I put in the code?

  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,870
    When you test the suform on its own, you are dealing with Me.
    Do you get a DateCompleted values when you test subform alone?
    Code:
    Private Sub Completed_AfterUpdate()
    Debug.print "In Completed after update "
    If Me.Completed = True Then
      Debug.print me.completed;Me.Name;Me.parent.Name
      Me.DateCompleted = Date
    End If
    End Sub

  5. #5
    Sienna is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    19
    I got it to work by moving the code to OnClick. The only reason I used AfterUpdate in the first place is because I had found code I borrowed online.

    This is my final code:

    Private Sub Completed_Click()
    If Me.Completed = True Then
    Me.DateCompleted = Now()
    End If
    End Sub

    Thanks for all of your help.

  6. #6
    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,870
    Did you get any results fro the debug.print???
    It's a great debugging technique.

  7. #7
    Sienna is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    19
    I haven't tried it, since I moving the code to OnClick worked. I'll give it a try later on. Can't do it now because I don't have exclusive access. People are using it.

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

Similar Threads

  1. Checked Box + Date = Checked box
    By ItsATJ in forum Access
    Replies: 12
    Last Post: 09-03-2013, 10:25 AM
  2. Forms, text box only visible when yes/no field checked
    By Remillard in forum Programming
    Replies: 6
    Last Post: 04-15-2013, 12:59 PM
  3. Replies: 1
    Last Post: 02-15-2013, 08:44 AM
  4. Replies: 4
    Last Post: 03-02-2012, 08:41 AM
  5. the last updated date and time
    By venu in forum Access
    Replies: 2
    Last Post: 04-02-2010, 08:11 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