Hi!
I have taken a standard code for duplicating a form with its subform, but it falls over when trying to append the subform to its table....
Reports an RT error 1034 "Too Few Parameters. Expected 1"
Error is @ Line
(dbFailOnError=128)
Debug.Print strSQL ....
INSERT INTO TblOrderitem ( OrderMainLink, PartNo, Description, Qty, UnitPrice, SubPrice, OrderItem_Spec, Location, Supply, DelTime ) SELECT 113 As NewID, PartNo, Description, QTY, UnitPrice, SubPrice, OrderItem_Spec, Location, Supply, DelTime FROM TblOrderitem WHERE OrderLinkID = 84;
Im pretty sure the rest of the code is fine, but cant figure it out the error, please help.
I have taken a standard code for duplicating a form with its subform, but it falls over when trying to append the subform to its table....
Code:
Private Sub OrderCopy_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 lngID As Long 'Primary key value of the new record.
'Save any edits first
If Me.Dirty Then
Me.Dirty = 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
'!OwnerID = Me.OwnerID
!TBLCustomerID = Me.TBLCustomerID
!OrderDate = Me.OrderDate
!OrderType = Me.OrderType
!EmployeeID = Me.EmployeeID
!ProjectRef = Me.ProjectRef
' !PONo = Me.PONo
!SalesRegion = Me.SalesRegion
!Commision = Me.Commision
' !SpecNo = Me.SpecNo
!Notes = Me.Notes
!OrderMainText = Me.OrderMainText
!DocumentsInc = Me.DocumentsInc
!DrawInc = Me.DrawInc
'!SupplyType = Me.SupplyType
.Update
'Save the primary key value, to use as the foreign key for the related records.
.Bookmark = .LastModified
lngID = !OrderID
'Duplicate the related records: append query.
If Me.[FRmQ_OrderItemSUB].Form.RecordsetClone.RecordCount > 0 Then
strSQL = "INSERT INTO TblOrderitem ( OrderMainLink, PartNo, Description, Qty, UnitPrice, SubPrice, OrderItem_Spec, Location, Supply, DelTime ) " & _
"SELECT " & lngID & " As NewID, PartNo, Description, Qty, UnitPrice, SubPrice, OrderItem_Spec, Location, Supply, DelTime " & _
"FROM TblOrderitem WHERE OrderLinkID = " & Me.OrderID & ";"
Debug.Print strSQL
DBEngine(0)(0).Execute strSQL, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no Order Items to Copy."
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, , "cmdDupe_Click"
Resume Exit_Handler
End Sub
Reports an RT error 1034 "Too Few Parameters. Expected 1"
Error is @ Line
Code:
DBEngine(0)(0).Execute strSQL, dbFailOnError
Debug.Print strSQL ....
INSERT INTO TblOrderitem ( OrderMainLink, PartNo, Description, Qty, UnitPrice, SubPrice, OrderItem_Spec, Location, Supply, DelTime ) SELECT 113 As NewID, PartNo, Description, QTY, UnitPrice, SubPrice, OrderItem_Spec, Location, Supply, DelTime FROM TblOrderitem WHERE OrderLinkID = 84;
Im pretty sure the rest of the code is fine, but cant figure it out the error, please help.
Last edited: