PC Review


Reply
Thread Tools Rate Thread

Copy a record using command button

 
 
Laura
Guest
Posts: n/a
 
      15th Oct 2003
I am trying to copy and paste a record in a table using a
command button. When I do this, it creates a table
called "Paste Error". I think it is because the table has
a primary key that is auto numbered. Here is the VB
behind the button:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.GoToRecord , , acNewRec
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, ,
acMenuVer70 'Paste Append
DoCmd.GoToRecord , , acLast

line two copies, line three creates a new record, line
three pastes and line four goes to the last record made,
theoretically. But it doesn't work.

Thanks for any help!
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      15th Oct 2003
Presumably this is a command button on a form, to duplicate the current
record.

The 'Paste Error' table might provide info on what went wrong.

Access can usually sort out the AutoNumber issue, but there are several
other problems with the wizard generated code, e.g.:
- Any unbound controls or controls bound to expressions? For example, an
unbound combo that nagivates records will mess up the process.

- Any chance the record could be dirty? If it can't be saved the duplicate
won't work.

Better code, with precise control over which fields are duplicated might
look like this:

If Me.Dirty Then 'Save any changes
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record.
MsgBox "Select a record to duplicate"
Else
With Me.RecordsetClone 'Point the clone set to this record.
.Bookmark = Me.Bookmark
'Go to a new record, and copy from the clone set.
RunCommand acCmdRecordsGotoNew
Me!SomeField = !SomeField
Me!AnotherField = !AnotherField
'etc.
End With
End If

--
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.

"Laura" <(E-Mail Removed)> wrote in message
news:2aef901c392b5$01bec040$(E-Mail Removed)...
> I am trying to copy and paste a record in a table using a
> command button. When I do this, it creates a table
> called "Paste Error". I think it is because the table has
> a primary key that is auto numbered. Here is the VB
> behind the button:
>
> DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
> DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
> DoCmd.GoToRecord , , acNewRec
> DoCmd.DoMenuItem acFormBar, acEditMenu, 5, ,
> acMenuVer70 'Paste Append
> DoCmd.GoToRecord , , acLast
>
> line two copies, line three creates a new record, line
> three pastes and line four goes to the last record made,
> theoretically. But it doesn't work.
>
> Thanks for any help!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Button Pictures Taken from Command Bar Button Icons acx@centrum.cz Microsoft Access Forms 0 2nd Dec 2007 01:23 PM
Copying data from current record into a new record using a command button Scott Microsoft Access Form Coding 1 8th Jul 2007 07:23 AM
VB's Command Button vs Form's Command Button Ronald Dodge Microsoft Excel Programming 3 24th May 2006 02:23 PM
Sub record not associated with main record when copy record button is used Ron V Microsoft Access Form Coding 0 21st May 2004 05:26 PM
Copy Value From Previous record Using Only Command Button 1aae Microsoft Access Form Coding 0 25th Apr 2004 04:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:07 AM.