L
lambchops218
I have a main customer form with a subform showing their services
(subfrm_servicesbyserviceagreement). When the customer wants to have a
scheduled pick up, I have a button called create work order. This opens a
work order form adding a new record. There is a subform called services by
work orders (as a customer could have one or many services) on the work order
form. I want to pre-populate this form with their services from the customer
screen, but allow them to change the services linked to the work order (not
save the changes in their customer file, but only for that particular work
order).
This is the code from the subform on the work order screen. THe problem
comes in when I try to update the recordset, it gives an error saying a
related record is required in tbl_workders, I believe meaning that the work
orders form has not written the new work order to the table. HOw do I get
that to happen before the subform loads? THe subform for the work order
services loads before the work order form. Can I change that?:
Set db = CurrentDb()
WorkOrdernum = DMax("WorkOrderNo", "tbl_WorkOrders") + 1
Set WOservices = Me.Recordset
Set services = Forms!frm_Customers! _
subfrm_ServicesbyServiceAgreement.Form.RecordsetClone
services.MoveFirst
If Not services.EOF Then
With services
.MoveFirst
Do Until services.EOF
WOservices.AddNew
WOservices.Fields("workOrderID") = WorkOrdernum
WOservices.Fields("ServiceCode") = .Fields("ServiceCode")
WOservices.Fields("UnitPrice") = .Fields("UnitPrice")
WOservices.Fields("Quantity") = .Fields("Quantity")
WOservices.Fields("UnitPrice") = .Fields("UnitPrice")
WOservices.Fields("Standardprice") = Me.StandardPrice.Value
'WOservices.Update
.MoveNext
Loop
End With
End If
Thanks!!!!
(subfrm_servicesbyserviceagreement). When the customer wants to have a
scheduled pick up, I have a button called create work order. This opens a
work order form adding a new record. There is a subform called services by
work orders (as a customer could have one or many services) on the work order
form. I want to pre-populate this form with their services from the customer
screen, but allow them to change the services linked to the work order (not
save the changes in their customer file, but only for that particular work
order).
This is the code from the subform on the work order screen. THe problem
comes in when I try to update the recordset, it gives an error saying a
related record is required in tbl_workders, I believe meaning that the work
orders form has not written the new work order to the table. HOw do I get
that to happen before the subform loads? THe subform for the work order
services loads before the work order form. Can I change that?:
Set db = CurrentDb()
WorkOrdernum = DMax("WorkOrderNo", "tbl_WorkOrders") + 1
Set WOservices = Me.Recordset
Set services = Forms!frm_Customers! _
subfrm_ServicesbyServiceAgreement.Form.RecordsetClone
services.MoveFirst
If Not services.EOF Then
With services
.MoveFirst
Do Until services.EOF
WOservices.AddNew
WOservices.Fields("workOrderID") = WorkOrdernum
WOservices.Fields("ServiceCode") = .Fields("ServiceCode")
WOservices.Fields("UnitPrice") = .Fields("UnitPrice")
WOservices.Fields("Quantity") = .Fields("Quantity")
WOservices.Fields("UnitPrice") = .Fields("UnitPrice")
WOservices.Fields("Standardprice") = Me.StandardPrice.Value
'WOservices.Update
.MoveNext
Loop
End With
End If
Thanks!!!!