Duplicate record and open form (1 Viewer)

JRPMD

Registered User.
Local time
Yesterday, 23:47
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:

June7

AWF VIP
Local time
Yesterday, 22:47
Joined
Mar 9, 2014
Messages
5,468
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?
 

JRPMD

Registered User.
Local time
Yesterday, 23:47
Joined
Nov 24, 2012
Messages
52
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.
 

JHB

Have been here a while
Local time
Today, 08:47
Joined
Jun 17, 2012
Messages
7,732
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
 

JRPMD

Registered User.
Local time
Yesterday, 23:47
Joined
Nov 24, 2012
Messages
52
How can I tag this thread solved ?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:47
Joined
Aug 30, 2003
Messages
36,125
If you edit the thread, you can change the prefix to Solved.
 

Users who are viewing this thread

Top Bottom