Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    incrementing date (2000 all updates)

    I want to set up a command button on a form, so that when the button is pressed it automatically creates 10 new records, each with the date one year apart.

    This should be easy, but my brain has gone cramped trying to figure it out.

    Here is one variation of the code I have tried...and I have tried several (I guess it's a while since I did Basic programming)...
    For x = 1 To 10
    DoCmd.GoToRecord , , acNewRec
    For y = 1 To 10
    Me.MyDate = DateAdd("yyyy", y, oldDate)
    Me.cboTime = timeTemp
    Me.cboEvent = eventTemp
    Me.Notes = Nz(notesTemp)
    Next
    Next


    What I am trying to accomplish is this: Say that I am on a record that has the date of January 1, 2007. When I push the command button, I want 10 new records created, with exactly the same information except for the MyDate field. The new records would have the dates of...
    January 1, 2008
    January 1, 2009
    January 1, 2010 etc. etc. etc. to 10 records

    Thanks.

    Tom

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: incrementing date (2000 all updates)

    Try this:

    oldDate = Me.MyDate
    For i = 1 To 10
    RunCommand acCmdSelectRecord
    RunCommand acCmdCopy
    RunCommand acCmdPasteAppend
    Me.MyDate = DateAdd("yyyy", i, oldDate)
    Next i

  3. #3
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: incrementing date (2000 all updates)

    Hans
    Well, that didn't quite work...because there was a message "the copy command isn't available right now."

    However, that put me on the right track. The following works...
    For x = 1 To 10
    DoCmd.GoToRecord , , acNewRec
    Me.MyDate = DateAdd("yyyy", x, oldDate)
    Me.cboTime = timeTemp
    Me.cboEvent = eventTemp
    Me.Notes = Nz(notesTemp)
    Next x


    I was making it more complicated than needed.

    Thanks.

    Tom

  4. #4
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: incrementing date (2000 all updates)

    Hans
    Actually, what you provided does work. It's just that I stuck in the DoCmd.GoToRecord,,acNewRec line in error. That is what caused the error message.

    Sorry.

    Thanks again.

    Tom

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •