Duplicating Data in a FORM Including all SUBFORMS!!!

Waldin

Registered User.
Local time
Today, 14:34
Joined
Oct 11, 2012
Messages
109
Good Morning All Computer Magicians

i have the below code that is supposed to duplicate the current data in a form including its subforms upon trying to edit data and create a new record/form.

but all it does is give me a error message saying:
Run Time Error '3164':
Field Cannot Be Updated.

below is the onDirty eventCode code, i hope i supplied enuff information.

Private Sub Form_Dirty(Cancel As Integer)
'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
TrackID = Me.TrackID
TrackID_Main = Me.TrackID_Main
BookedInBy = Me.BookedInBy
BookInMethod = Me.BookInMethod
BookInDate = Me.BookInDate
BookInComments = Me.BookInComments
BookInDamages = Me.BookInDamages
ClaimNumber = Me.ClaimNumber
AuthorisationStatusID = Me.AuthorisationStatusID
WorkProviderID = Me.WorkProviderID
EstimatorID = Me.EstimatorID
PolicyNumber = Me.PolicyNumber
OtherReference = Me.OtherReference
RepairTypeID = Me.RepairerTypeID
InsuredAmount = Me.InsuredAmount
ExcessAmount = Me.ExcessAmount
DiscountPercentage = Me.DiscountPercentage
EstimatedRepairCost = Me.EstimatedRepairCost
RepairsAuthorisedID = Me.RepairsAuthorisedID
Damages = Me.Damages
DateOfAccident = Me.DateOfAccident
RepairStartDate = Me.RepairStartDate
RepairEndDate = Me.EstimatedRepairDate
EstimatedRepairTime = Me.EstimatedRepairTime
ActualRepairTime = Me.ActualRepairTime
PartsOrderedDate = Me.PartsOrderedDate
HireCarStartDate = Me.HireCarStartDate
HireCarEndDate = Me.HireCarEndDate
UnderWarranty = Me.UnderWarranty
WarrantyExpires = Me.WarrantyExpires
PreAccidentCondition = Me.PreAccidentCondition
SteeringCondition = Me.SteeringCondition
BrakesPedalTravel = Me.BrakesPedalTravel
PleaceOfInspection = Me.PleaceOfInspection
SeverityOfImpact = Me.SeverityOfImpact
VehicleStatusOnInspection = Me.VehicleStatusOnInspection
DateOfVehicleInspection = Me.DateOfVehicleInspection
TyreCondition = Me.TyreCondition
TreadDepthLHF = Me.TreadDepthLHF
TreadDepthRHF = Me.TreadDepthRHF
TreadDepthRHR = Me.TreadDepthRHR
TreadDepthLHR = Me.TreadDepthLHR
ShopID = Me.ShopID
CustomerID = Me.CustomerID
CompanyName = Me.CompanyName
CustomerName = Me.CustomerName
CustomerSurname = Me.CustomerSurname
Address = Me.Address
Suburb = Me.Suburb
City = Me.City
PostalCode = Me.PostalCode
PhoneNumber = Me.PhoneNumber
FaxNumber = Me.FaxNumber
CellNumber = Me.CellNumber
SendViaCell = Me.SendViaCell

'etc for other fields.
.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.[Quotation Subform].Form.RecordsetClone.RecordCount > 0 Then
strSql = "INSERT INTO [Quotation Details] ( TrackID, TrackID_Main, BookedInBy, BookInMethod, BookInDate, BookInComments, BookInDamages, ClaimNumber, AuthorisationStatusID, WorkProviderID, EstimatorID, PolicyNumber, OtherReference, RepairerTypeID, InsuredAmount, ExcessAmount, DiscountPercentage, EstimatedRepairCost, RepairsAuthorisedID, Damages, DateOfAccident, RepairStartDate, RepairEndDate, EstimatedrepairDate, EstimatedRepairTime, ActualRepairTime, PartsOrdered, PartsOrderedDate, HireCarStartDate, HireCarEndDate, UnderWarranty, WarrantyExpires, PreAccidentCondition, SteeringCondition, BrakesPedalTravel, PleaceOfInspection, SeverityOfImpact, VehicleStatusOnInspection, DateOfVehicleInspection, TyreCondition, TreadDepthLHF, TreadDepthLHR, TreadDepthRHF, TreadDepthRHR, ShopID, CustomerID, CompanyName, CustomerName, CustomerSurname, Address, City, PostalCode, PhoneNumber, FaxNumber, CellNumber, SendViaCell ) " & _
"SELECT " & lngID & " As NewID, TrackID, TrackID_Main, BookedInBy, BookInMethod, BookInDate, BookInComments, BookInDamages, ClaimNumber, AuthorisationStatusID, WorkProviderID, EstimatorID, PolicyNumber, OtherReference, RepairerTypeID, InsuredAmount, ExcessAmount, DiscountPercentage, EstimatedRepairCost, RepairsAuthorisedID, Damages, DateOfAccident, RepairStartDate, RepairEndDate, EstimatedrepairDate, EstimatedRepairTime, ActualRepairTime, PartsOrdered, PartsOrderedDate, HireCarStartDate, HireCarEndDate, UnderWarranty, WarrantyExpires, PreAccidentCondition, SteeringCondition, BrakesPedalTravel, PleaceOfInspection, SeverityOfImpact, VehicleStatusOnInspection, DateOfVehicleInspection, TyreCondition, TreadDepthLHF, TreadDepthLHR, TreadDepthRHF, TreadDepthRHR, ShopID, CustomerID, CompanyName, CustomerName, CustomerSurname, Address, City, PostalCode, PhoneNumber, FaxNumber, CellNumber, SendViaCell " & _
"FROM [Quotation Details] WHERE TrackID = " & Me.TrackID & ";"
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
 
this is not the comlete fields in my tables i just added half to the code th see if it would work, and its atleast supposed to work on the fields that i added in the code isnt it?
 

Users who are viewing this thread

Back
Top Bottom