Connecting Tech Pros Worldwide Help | Site Map

Making a duplicate record

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 16th, 2006, 05:05 PM
2D Rick
Guest
 
Posts: n/a
Default Making a duplicate record

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


  #2  
Old May 17th, 2006, 09:15 AM
Allen Browne
Guest
 
Posts: n/a
Default Re: Making a duplicate record

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" <rbrowniii@compuserve.com> wrote in message
news:1147798889.621846.40930@j33g2000cwa.googlegro ups.com...[color=blue]
> 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[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.