By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,586 Members | 623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,586 IT Pros & Developers. It's quick & easy.

Making a duplicate record

P: n/a
Access2003 in XP
If I open a form to a specific record and click on a command button
with the following code I get a duplcate record:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
OR
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste
Append

But if I try to run this from and event such as OnLoad, OnCurrent or
OnTimer I get an error message.
"The command or action 'Copy' isn't available now."

I know going in that I what a duplicate record so is there a fix for
this?

Thanks, Rick

May 16 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
A form can have many records. Do you always want to duplicate the *first*
one? Sounds odd.

The Load event is too early to try the paste append.

The Current event is also unusable: As soon as you move to any record, if
the code worked, Access would duplicate it which would load the new record
which would fired the Curent event which would copy it and move to the new
record and so the Current event would fire again and... Fortunately for you,
this doesn't work either.

If there is a valid reason for duplicating the first record in the form as
soon as it opens, I am guessing that you are opening the form with a
WhereCondition so that only the one desired record is loaded. If this is the
case, you could OpenForm, and then trigger the Click event of the button so
the code runs automatically. If the command button is named Command1, you
need to remove the Private keyword from the start of this line:
Private Sub Command1_Click()

You can then execute the code like this:
DoCmd.OpenForm "Form1", WhereCondition:="ID = 99"
Call Form_Form1.Command1_Click

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"2D Rick" <rb*******@compuserve.com> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
Access2003 in XP
If I open a form to a specific record and click on a command button
with the following code I get a duplcate record:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend
OR
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste
Append

But if I try to run this from and event such as OnLoad, OnCurrent or
OnTimer I get an error message.
"The command or action 'Copy' isn't available now."

I know going in that I what a duplicate record so is there a fix for
this?

Thanks, Rick

May 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.