The fastest and simplest way is to use DAO and the RecordsetClone of the form:
Private Sub cmdDuplicate_Click()
Dim rstSource As DAO.Recordset
Dim rstInsert As DAO.Recordset
Dim fld As DAO.Field
If Me.NewRecord = True Then Exit Sub
Set rstInsert = Me.RecordsetClone
Set rstSource = rstInsert.Clone
With rstSource
If .RecordCount > 0 Then
' Go to the current record.
.Bookmark = Me.Bookmark
With rstInsert
.AddNew
For Each fld In rstSource.Fields
With fld
If .Attributes And dbAutoIncrField Then
' Skip Autonumber or GUID field.
ElseIf .Name = "SomeFieldToPreset" Then
rstInsert.Fields(.Name).Value = SomeValue
ElseIf .Name = "SomeFieldToExclude" Then
' Leave blank
Else
' All other fields.
' Copy field content.
rstInsert.Fields(.Name).Value = .Value
End If
End With
Next
.Update
' Go to the new record and sync form.
.MoveLast
Me.Bookmark = .Bookmark
.Close
End With
End If
.Close
End With
Set rstInsert = Nothing
Set rstSource = Nothing
End Sub
This moves the form from the current record to the new record. You can easily modify that to pick the new ID and open the other form with the new record.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…