Re: Duplicate the record in form and subform
- From: Andy <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 16 Dec 2007 01:31:00 -0800
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!
Here is the code :
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" wrote:
That's right, Andy.
If the primary key is not an Autonumber, you must assign something to it.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Beetle" <Beetle@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0C90F455-E349-40F2-83A9-1E5EAD5AF577@xxxxxxxxxxxxxxxx
Whatever method you're using to create your PK is going to have to be done
programmatically in your code i.e.
With Me.RecordsetClone
.AddNew
![PK field] = some value
!CustomerID = Me.CustomerID
!EmployeeID = Me.EmployeeID
!OrderDate = Date
'etc for other fields.
.Update
--
_________
Sean Bailey
"Andy" wrote:
Hi Allen,
Sorry for the typo error on the field name! Have corrected but another
error
message is "error#3058, primary key value can not be null" caused by
below
line :
.update
Have mentioned that my primary key value is not a autonumber, please
advise
how to change the code to fit my database.
Thanks again!
"Allen Browne" wrote:
Presumably we are talking about this article:
http://allenbrowne.com/ser-57.html
The "Item not found" error was caused by which line?
Whichever line it is, you have some name Access can't identify, e.g.
you
have not changed the field names to match what's in your form.
"Andy" <Andy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F433142D-F96C-41EC-AD9F-8408A6D669A4@xxxxxxxxxxxxxxxx
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!
- Follow-Ups:
- Re: Duplicate the record in form and subform
- From: Allen Browne
- Re: Duplicate the record in form and subform
- References:
- Re: Duplicate the record in form and subform
- From: Allen Browne
- Re: Duplicate the record in form and subform
- From: Beetle
- Re: Duplicate the record in form and subform
- From: Allen Browne
- Re: Duplicate the record in form and subform
- Prev by Date: Changing recordset/serverfilter from another form
- Next by Date: Re: Duplicate the record in form and subform
- Previous by thread: Re: Duplicate the record in form and subform
- Next by thread: Re: Duplicate the record in form and subform
- Index(es):
Relevant Pages
|