Duplicating a Record in a Form that's based on a Query

G

Guest

I want to create a button that duplicates a record in a Form that's based on
a query.


I tried the create a button tool and it puts in the following code:

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

But it doesn't work. It gives me the following error:

Records that Microsoft Office Access was unable to pase have been inserted
into a new table called 'Paste Errors.'
 
M

Marshall Barton

Christian said:
I want to create a button that duplicates a record in a Form that's based on
a query.


I tried the create a button tool and it puts in the following code:

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

But it doesn't work. It gives me the following error:

Records that Microsoft Office Access was unable to pase have been inserted
into a new table called 'Paste Errors.'


I would have expected you to get some kind of a key
violation message (if there are any unique fields being
copied).

The wizard's code is rather simple minded and doesn't work
in all cases.

More than likely, you really don't want to copy every field
in the table (especially not an autonumber field), so a more
descriminating approach would be advisable.

With Me.RecordsetClone
.AddNew
'''' don't copy primary key field
![this field] = Me.[this field]
![that field] = Me.[that field]
![other field] = Me.[other field]
![date field] = Date
. . .
.Update
End With
 
G

Guest

I entered the code you suggested and am getting an error:

"You entered an expression that has an invalid reference to the
RecordsetClone property."


Marshall Barton said:
Christian said:
I want to create a button that duplicates a record in a Form that's based on
a query.


I tried the create a button tool and it puts in the following code:

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

But it doesn't work. It gives me the following error:

Records that Microsoft Office Access was unable to pase have been inserted
into a new table called 'Paste Errors.'


I would have expected you to get some kind of a key
violation message (if there are any unique fields being
copied).

The wizard's code is rather simple minded and doesn't work
in all cases.

More than likely, you really don't want to copy every field
in the table (especially not an autonumber field), so a more
descriminating approach would be advisable.

With Me.RecordsetClone
.AddNew
'''' don't copy primary key field
![this field] = Me.[this field]
![that field] = Me.[that field]
![other field] = Me.[other field]
![date field] = Date
. . .
.Update
End With
 
M

Marshall Barton

I think that means that the form is unbound (i.e. no
recordset to clone). Either that or you put the code in an
inappropriate location. OTOH, maybe you didn't translate it
to your situation correctly.

More information is needed.
--
Marsh
MVP [MS Access]

I entered the code you suggested and am getting an error:

"You entered an expression that has an invalid reference to the
RecordsetClone property."


Marshall Barton said:
Christian said:
I want to create a button that duplicates a record in a Form that's based on
a query.

I tried the create a button tool and it puts in the following code:

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

But it doesn't work. It gives me the following error:

Records that Microsoft Office Access was unable to pase have been inserted
into a new table called 'Paste Errors.'


I would have expected you to get some kind of a key
violation message (if there are any unique fields being
copied).

The wizard's code is rather simple minded and doesn't work
in all cases.

More than likely, you really don't want to copy every field
in the table (especially not an autonumber field), so a more
descriminating approach would be advisable.

With Me.RecordsetClone
.AddNew
'''' don't copy primary key field
![this field] = Me.[this field]
![that field] = Me.[that field]
![other field] = Me.[other field]
![date field] = Date
. . .
.Update
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top