Results 1 to 4 of 4
  1. #1
    Newby is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Posts
    60

    Update date field with a form button command

    Good morning

    I am setting up a "to_do" list in access. One of the field is the date the task was last completed. I want a button to update that date to the current date for the record that i am viewing on the form. Below is the code that I am using. When I click on my button, it updates the first record in my to-do table but not the current record displayed in my form.

    Private Sub Cmd_Update_Click()
    Dim DB As Database
    Dim rs As Recordset
    Dim i As Long


    On Error GoTo Command4_Click_Error

    Set DB = CurrentDb
    Set rs = DB.OpenRecordset("to_dos")
    rs.Edit
    rs.Fields("DateCompleted") = Now()
    rs.Update



    On Error GoTo 0
    Exit Sub
    Command4_Click_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description _
    & ") in procedure Command4_Click of VBA Document Form_Form5"
    End Sub

    John

  2. #2
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    John -

    Try...
    replacing your code with

    Me.DateCompleted = Now()

    All the best,

    Jim

  3. #3
    Newby is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Posts
    60

    Thanks.

    Quote Originally Posted by ketbdnetbp View Post
    John -

    Try...
    replacing your code with

    Me.DateCompleted = Now()

    All the best,

    Jim


    It works. "Me." pretty means current record?

    John

  4. #4
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254
    John - Glad you got it working. See attached for more info about the Me property.

    All the best,

    JimFrom Microsoft Office Access 2003 Visual Basic Reference.doc

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

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2012, 02:50 PM
  2. Replies: 3
    Last Post: 08-16-2012, 11:25 AM
  3. Replies: 12
    Last Post: 03-14-2012, 10:54 AM
  4. Replies: 5
    Last Post: 02-21-2012, 07:33 AM
  5. Command button for time & date
    By joet5402 in forum Forms
    Replies: 2
    Last Post: 12-20-2007, 02:59 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