Allen,
Have checked the names in the SQL statement are correct, what's the
problem?
BTW, any change in the SQL statement if the PK value is string?
Here is my code, please check, thanks sooooooooooo much!
Private Sub Command36_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 String 'Primary key value of the new record.
'Save and 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
![QUOTATION NO] = InputBox("Please enter the quotation
number :", "Hello Kitty")
![COMPANY NO] = Me.[COMPANY NO]
![CUSTOMER NO] = Me.[CUSTOMER NO]
![LOCATION NO] = Me.[LOCATION NO]
![QUOT DATE] = DATE
![EFFECTIVE DATE] = Me.[EFFECTIVE DATE]
![PAYMENT TERMS] = Me.[PAYMENT TERMS]
![DELIVERY TERMS] = Me.[DELIVERY TERMS]
![ITEM HEADER] = Me.[ITEM HEADER]
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = ![QUOTATION NO]
'Duplicate the related records: append query.
If Me.[QUOTATION TABLE DETAILS
subform].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [QUOTATION TABLE DETAILS] (
[QUOTATION
NO], [ITEM NO], [ITEM CONTENT], [QTY], [UNIT], [UNIT PRICE] ) " & _
"SELECT " & lngID & " As NewID, [ITEM NO], [ITEM
CONTENT], [QTY], [UNIT], [UNIT PRICE] " & _
"FROM [QUOTATION TABLE DETAILS] WHERE [QUOTATION NO] =
"
& Me.[QUOTATION NO] & ";"
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, ,
"cmdDupe_Click"
Resume Exit_Handler
End Sub
Allen Browne said:
The request for a parameter means you have a name Access doesn't
recognise.
So some name in the SQL statement is no correct.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
Thanks, Beetle & Allen,
Have changed the code as below but got an error message "Error#3061,
parameter not much enough, expected is 1" caused by below line :
DBEngine(0)(0).Execute strSql, dbFailOnError
Appreciate your expert commnts! Thanks in advance!