I am trying to set up "Cloning" on a form so that we don't have to enter all info every time when most of it is the same.
I have the main form [frmRFQInput] linked to [tblRFQ]:
[RFQNumber]
[RFQDate]
[RFQDueDate]
[Supplier]
[BuyerName]
[Notes]
and a subform [frmRFQInputsubform]linked to [tblRFQItems]:
[ID]......(linked to RFQNumber)
[PartNumber]
[Revision]
[Material]
[ProcessDescription]
[Qty1]
[Qty2]
[Qty3]
[Notes]
I am still getting errors in the code and I am not sure where I have gone wrong.
I have the main form [frmRFQInput] linked to [tblRFQ]:
[RFQNumber]
[RFQDate]
[RFQDueDate]
[Supplier]
[BuyerName]
[Notes]
and a subform [frmRFQInputsubform]linked to [tblRFQItems]:
[ID]......(linked to RFQNumber)
[PartNumber]
[Revision]
[Material]
[ProcessDescription]
[Qty1]
[Qty2]
[Qty3]
[Notes]
I am still getting errors in the code and I am not sure where I have gone wrong.
Code:
Private Sub Command35_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the subform.
Dim strSql As String 'Sql statement
Dim ldslD As Long 'Primary key value of the new record.
'Save any edits first
If Me.Dirty Then
Me.Dirry=False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
RFQDate=Date
RFQDueDate="Enter Due Date"
Supplier="Enter Supplier"
BuyerName=BuyerName
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the related records.
.Bookmark=LastModified
ID=!RFQNumber
'Duplicate the related RFQ records: append query
If Me.[frmRFQInputsubform].Form.RecordsetClone.RecordCount>0 Then
strSql+"INSERT INTO [tblRFQItems]
(ID,PartNumber,Revision,Material,ProcessDescription,Qty1,Qty2,Qty3,Notes) "&_
"SELECT"& ID & "As NewID,PartNumber,Revision,Material,ProcessDescription,Qty1,Qty2,Qty3,Notes" &_
"FROM [tblRFQItems] WHERE ID="& Me.RFQNumber & ";"
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
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error" & Err.Number & "-" & Err.Description, , "Command35_Click"
Resume Exit_Handler
End Sub