Private Sub cmdCopyQuote_Click()
On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the subform.
Dim NewQuoteID As Long 'Primary key value of the new record.
Dim OldQuoteID As Long
Dim db As DAO.Database
Dim qd As DAO.QueryDef
'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."
Exit Sub
End If
'Duplicate the main record: add to form's clone.
OldQuoteID = Me.QuoteID
With Me.RecordsetClone
.AddNew
!CustID = Me.cboCustID
!JobName = Me.JobName
!Notes = Me.Notes
!TermsID = Me.TermsID
!ShippingID = Me.ShippingID
!CustConID = Me.cboCustConID
!CustLocID = Me.cboCustLocID
!QuoteNumber = Nz(DMax("QuoteNumber", "tblQuotes"), 0) + 1
!QuoteDate = Date
!Expires = Date + 30
.Update
'Save the primary key value, to use as the foreign key for the related records.
.Bookmark = .LastModified
NewQuoteID = !QuoteID
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
'' copy details
Set qd = db.QueryDefs!qCopyAppendQuoteAcc
qd.Parameters!EnterOldQuoteID = OldQuoteID
qd.Parameters!EnterNewQuoteID = NewQuoteID
qd.Execute dbSeeChanges
Me.SfrmQuoteDetails.Requery
Set db = Nothing
Exit_Handler:
Exit Sub
Err_Handler:
Select Case Err.Number
Case 3021, 2501 ' update cancelled
Resume Exit_Handler
Case Else
MsgBox Err.Number & "--" & Err.Description
Resume Exit_Handler
End Select
End Sub