Duplicate the record in form and subform

A

Andy

Hi Allen Browne,

I try to use your code to duplicate the record in form and subform but I got
a error message "Error#3265". BTW, my primary key value is not autonumber,
how to change the code to fit my database?
Thanks for your expert comments in advance!
 
B

Ben

I used the code you guys provided and I'm getting the main form to duplicate
but not the subform, here's the code.

With Me.RecordsetClone
.AddNew
!ProjectName = Me.ProjectName
!DEASRALeads = Me.DEASRALeads
!Phase1 = Me.Phase1
!Phase2 = Me.Phase2
!Phase3 = Me.Phase3
!Phase4 = Me.Phase4
!Phase5 = Me.Phase5
!Phase1Status = Me.Phase1Status
!Phase2Status = Me.Phase2Status
!Phase3Status = Me.Phase3Status
!Phase4Status = Me.Phase4Status
!Phase5Status = Me.Phase5Status
!Other = Me.Other


'etc for other fields.
.Update

'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !WebFarmID



'Duplicate the related records: append query.
If Me.[frmWebFarmAIs].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [tblWebFarmAIs] ( WebFarmAIID,
ActionItemsNew, Owner, WebFarmID ) " & _
"SELECT " & lngID & " As NewID, WebFarmAIID,
ActionItemsNew, Owner, WebFarmID " & _
"FROM [tblWebFarmAIs] WHERE WebFarmID = " & Me.WebFarmID
& ";"
'DBEngine(0)(0).Execute strSql, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no related
records."
End If

'Display the new duplicate.
Me.Bookmark = .LastModified
End With

Thanks

Ben
 

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