C
Chris
I am trying to duplicate a record that is shown on form in order to create
a new record with the same data but new revision number. The following code
used to work but for some reason now gives me a run time error 3426 This
action was cancelled by an associated object and the .addnew is highlighted.
Darned if I can figure it out. Using Access 2000 with SP3 references to ADO
and DAO. Database has been split.
Hope someone can point me in the write direction.
Private Sub cmdRevise_Click()
Dim strSQL As String
Dim rec As DAO.Recordset
Dim strQuoteID As String
Dim db As DAO.Database
Set db = CurrentDb()
Set rec = Form_Quotes.RecordsetClone
Me.RecordsetClone.Bookmark = Form_Quotes.Bookmark
If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record
With rec
.AddNew
!QuoteDate = Date
!QuoteNumber = Me.QuoteNumber
!ProjectID = Me.ProjectID
!EmployeeID = Me.EmployeeID
!RevisionNumber = Me.RevisionNumber + 1
!QuoteID = Me.QuoteNumber & ("-R" + CStr(Me.RevisionNumber +
1)) 'primary key
.Update
.Bookmark = .LastModified
strQuoteID = !QuoteID
'Duplicate the related records.
If Form_QuoteDetails.Form.RecordsetClone.RecordCount > 0 Then
strSQL = "INSERT INTO QuoteDetails ( QuoteID,
ProductID,UnitPrice,Discount,Quantity) " & _
"SELECT " & "'" & strQuoteID & "'" & " As
NewQuoteID,QuoteDetails.ProductID, QuoteDetails.UnitPrice," _
& " QuoteDetails.Discount, QuoteDetails.Quantity FROM
QuoteDetails WHERE(QuoteDetails.QuoteID = " & "'" & Me.QuoteID & "'" & ");"
Debug.Print strSQL
db.Execute strSQL, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no related
records."
End If
'Display the duplicate.
Me.Bookmark = .LastModified
End With
End If
Set db = Nothing
End Sub
a new record with the same data but new revision number. The following code
used to work but for some reason now gives me a run time error 3426 This
action was cancelled by an associated object and the .addnew is highlighted.
Darned if I can figure it out. Using Access 2000 with SP3 references to ADO
and DAO. Database has been split.
Hope someone can point me in the write direction.
Private Sub cmdRevise_Click()
Dim strSQL As String
Dim rec As DAO.Recordset
Dim strQuoteID As String
Dim db As DAO.Database
Set db = CurrentDb()
Set rec = Form_Quotes.RecordsetClone
Me.RecordsetClone.Bookmark = Form_Quotes.Bookmark
If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record
With rec
.AddNew
!QuoteDate = Date
!QuoteNumber = Me.QuoteNumber
!ProjectID = Me.ProjectID
!EmployeeID = Me.EmployeeID
!RevisionNumber = Me.RevisionNumber + 1
!QuoteID = Me.QuoteNumber & ("-R" + CStr(Me.RevisionNumber +
1)) 'primary key
.Update
.Bookmark = .LastModified
strQuoteID = !QuoteID
'Duplicate the related records.
If Form_QuoteDetails.Form.RecordsetClone.RecordCount > 0 Then
strSQL = "INSERT INTO QuoteDetails ( QuoteID,
ProductID,UnitPrice,Discount,Quantity) " & _
"SELECT " & "'" & strQuoteID & "'" & " As
NewQuoteID,QuoteDetails.ProductID, QuoteDetails.UnitPrice," _
& " QuoteDetails.Discount, QuoteDetails.Quantity FROM
QuoteDetails WHERE(QuoteDetails.QuoteID = " & "'" & Me.QuoteID & "'" & ");"
Debug.Print strSQL
db.Execute strSQL, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no related
records."
End If
'Display the duplicate.
Me.Bookmark = .LastModified
End With
End If
Set db = Nothing
End Sub