Duplicate record and open form

JRPMD

Registered User.
Local time
Today, 13:11
Joined
Nov 24, 2012
Messages
52
Hello ,I have a table in a database with quite similar records , and a few changes in each new record.
So I need a code that duplicate the last record from a form and open another form to modified this record.
I used this two codes each one in a different command button and it works, but not if I tried it togheter in the same command button.
Is it possible to make a command button with this two actions?
Thank you very much!
Code:
Private Sub Comando351_Click()
On Error GoTo Err_Comando351_Click
   DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdRecordsGoToNew
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdPaste

Exit_Comando351_Click:
    Exit Sub

Err_Comando351_Click:
    MsgBox Err.Description
    Resume Exit_Comando351_Click
End Sub
___________________________________________________________
Private Sub Comando349_Click()
On Error GoTo Comando349_Click_Err
DoCmd.OpenForm "Indicaciones para red4", acNormal, "", "", , acNormal
Comando349_Click_Exit:
    Exit Sub
Comando349_Click_Err:
    MsgBox Error$
    Resume Comando349_Click_Exit
End Sub
 
Last edited by a moderator:
Need an ending [/CODE] tag to format text as code in post.

How can code in button 349 know which record to open form to?
 
Sorry I didn't wrote the ending tag
Code:
.
The form is based in a query  with a descendig date order field , so it opens the last , modified record.
 
In the button's click event, paste the below, (you should use meaningful name for you controls/button, in a short time you've forgotten what "Comando351" does.)!
A meaningful name could be "CopyRecord".
Code:
  DoCmd.RunCommand acCmdSelectRecord
  DoCmd.RunCommand acCmdCopy
  DoCmd.OpenForm "Indicaciones para red4", acNormal, , , , acNormal
In the form "Indicaciones para red4" open event, paste the below.
Code:
Private Sub Form_Open(Cancel As Integer)
  DoCmd.RunCommand acCmdRecordsGoToNew
  DoCmd.RunCommand acCmdSelectRecord
  DoCmd.RunCommand acCmdPaste
End Sub
 
If you edit the thread, you can change the prefix to Solved.
 

Users who are viewing this thread

Back
Top Bottom