Duplicate Record Command Button goes to previous record

B

Bdehning

How do I stop my form from going to the previous record
when I enter a field after hitting the command button to
duplicate a record.

I want to be able to modify the duplciated record and have
the ID number advance.
 
S

Sandra Daigle

That would depend on what code you are using to duplicate the record - post
your code. Otherwise, here is some code that I sometimes use for duplicating
a record:

This code will 'clone' the current record - attach it to whichever event
makes sense for you.

Dim rst As Dao.Recordset
Dim fld As Dao.Field
Dim lngCustid As Long
Set rst = Me.RecordsetClone.Clone
Me.RecordsetClone.Bookmark = Me.Bookmark
rst.Bookmark = Me.Bookmark
With Me.RecordsetClone
rst.AddNew
For Each fld In .Fields
'skip the primary key field -
'chg CustomerID to the name of your primary key field
If fld.Name <> "Customerid" Then
rst.Fields(fld.Name).Value = fld.Value
End If
Next fld
' If your Primary key (Customerid) is autonum you don't need this
' otherwise, replace this with whatever method you use for getting
' the next primary key value. This one is a simple incrementing value
'
lngCustid = Nz(DMax("Customerid", "Customers"), 0) + 1
rst.Fields("Customerid") = lngCustid
' Update the recordset with the new value
rst.Update
rst.Bookmark = rst.LastModified
' set the form's book mark to the new record
Me.Bookmark = rst.Bookmark
End With
Set rst = Nothing
Set fld = Nothing
 
G

Guest

Sandra
Actually just trying to use the built in Command Button Code for duplicating a record. It works on a new database but not on ones I have been using for a while. Here is the code.

Private Sub Command44_Click(
On Error GoTo Err_Command44_Clic

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

Exit_Command44_Click
Exit Su

Err_Command44_Click
MsgBox Err.Descriptio
Resume Exit_Command44_Clic

End Sub
 

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

Top