J
Joan
Hi,
I am having trouble getting an update query to work I am running it on an
AfterUpdate event of a control on one subform and want to update the
recordset of another subform on the main form. I am using some of the
controls on the first subform as parameters for the update query. I've tried
passing the parameter values to the QueryDef via VBA but the update does not
run. The main form (EditMode) is an EditDeleteInvoice form and there is a
subform call EditDog with Dogs that have been sold and were invoiced
earlier. There is also a form called AddDogtoInv where the user can enter a
dog number of a dog that was added (sold) after the invoice was recorded but
before it is sent to the store(customer). The AddDogtoInv form essentially
adds the Dog Number entered and the Invoice Number of the main form to the
Sales table. The other dogs listed in the EditDog subform were earlier added
to the Sales table.
When I enter a Dog Number in the AddDogtoInv subform and tab, the dogs
record appears in the EditDog form but the [Store] field is not updated.
Could someone take a look at my code and see if you can see what I am doing
wrong? Thank you so much.
Joan
The following three lines of code on the After Update event of
Subform!AddDogtoInv![DogN], essentially updates the EditDog subform with the
just added dog's record to the Sales table.
Me.Recalc
Me.Requery
Forms![EditDeleteInvoice]![EditDog].Requery
Also below is the SQL of my update query:
PARAMETERS [Forms]![EditDeleteInvoice]![AddDogtoInv]![DogN] Long,
[Forms]![EditDeleteInvoice]![AddDogtoInv]![txtInvoiceNumber] Long;
UPDATE qryAddDogtoInv SET qryAddDogtoInv.Store =
Forms!EditDeleteInvoice!StoreCode
WHERE (((qryAddDogtoInv.[Dog
Number])=[Forms]![EditDeleteInvoice]![AddDogtoInv]![DogN]) AND
((qryAddDogtoInv.[Invoice
Number])=[Forms]![EditDeleteInvoice]![AddDogtoInv]![txtInvoiceNumber]));
And my code:
Private Sub DogN_AfterUpdate()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim stRet As String
Dim qdf As DAO.QueryDef
Dim rs2 As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qryAddDogtoInv", dbOpenDynaset) ' the
query for the AddDogtoInv subform
Set rs2 = db.OpenRecordset("qryInvoiceSubEdit", dbOpenDynaset) ' the
query for the EditDog subform
stDog = Me.DogN
stRet = Me.Returned
stInvoice = Me.txtInvoiceNumber
Me.Recalc
Me.Requery
Forms![EditDeleteInvoice]![EditDog].Requery
With rs
If .EditMode = adEditInProgress Then
Me.Recordset.Update
End If
.Requery
End With
Set qdf = db.QueryDefs("SaleReturnAddDogStore")
'Execute Update query to set [Store] in dog record added to
invoice(EditDog subform) to store value in the main form.
With qdf
.Parameters("[Forms]![EditDeleteInvoice]![AddDogtoInv]![DogN]")
= stDog
..Parameters("[Forms]![EditDeleteInvoice]![AddDogtoInv]![txtInvoiceNumber]")
= stInvoice
.Execute
End With
rs.Requery
Me.Recalc
rs2.Requery
Forms![EditDeleteInvoice]![AddDogtoInv].Requery
End Sub
I am having trouble getting an update query to work I am running it on an
AfterUpdate event of a control on one subform and want to update the
recordset of another subform on the main form. I am using some of the
controls on the first subform as parameters for the update query. I've tried
passing the parameter values to the QueryDef via VBA but the update does not
run. The main form (EditMode) is an EditDeleteInvoice form and there is a
subform call EditDog with Dogs that have been sold and were invoiced
earlier. There is also a form called AddDogtoInv where the user can enter a
dog number of a dog that was added (sold) after the invoice was recorded but
before it is sent to the store(customer). The AddDogtoInv form essentially
adds the Dog Number entered and the Invoice Number of the main form to the
Sales table. The other dogs listed in the EditDog subform were earlier added
to the Sales table.
When I enter a Dog Number in the AddDogtoInv subform and tab, the dogs
record appears in the EditDog form but the [Store] field is not updated.
Could someone take a look at my code and see if you can see what I am doing
wrong? Thank you so much.
Joan
The following three lines of code on the After Update event of
Subform!AddDogtoInv![DogN], essentially updates the EditDog subform with the
just added dog's record to the Sales table.
Me.Recalc
Me.Requery
Forms![EditDeleteInvoice]![EditDog].Requery
Also below is the SQL of my update query:
PARAMETERS [Forms]![EditDeleteInvoice]![AddDogtoInv]![DogN] Long,
[Forms]![EditDeleteInvoice]![AddDogtoInv]![txtInvoiceNumber] Long;
UPDATE qryAddDogtoInv SET qryAddDogtoInv.Store =
Forms!EditDeleteInvoice!StoreCode
WHERE (((qryAddDogtoInv.[Dog
Number])=[Forms]![EditDeleteInvoice]![AddDogtoInv]![DogN]) AND
((qryAddDogtoInv.[Invoice
Number])=[Forms]![EditDeleteInvoice]![AddDogtoInv]![txtInvoiceNumber]));
And my code:
Private Sub DogN_AfterUpdate()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim stRet As String
Dim qdf As DAO.QueryDef
Dim rs2 As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qryAddDogtoInv", dbOpenDynaset) ' the
query for the AddDogtoInv subform
Set rs2 = db.OpenRecordset("qryInvoiceSubEdit", dbOpenDynaset) ' the
query for the EditDog subform
stDog = Me.DogN
stRet = Me.Returned
stInvoice = Me.txtInvoiceNumber
Me.Recalc
Me.Requery
Forms![EditDeleteInvoice]![EditDog].Requery
With rs
If .EditMode = adEditInProgress Then
Me.Recordset.Update
End If
.Requery
End With
Set qdf = db.QueryDefs("SaleReturnAddDogStore")
'Execute Update query to set [Store] in dog record added to
invoice(EditDog subform) to store value in the main form.
With qdf
.Parameters("[Forms]![EditDeleteInvoice]![AddDogtoInv]![DogN]")
= stDog
..Parameters("[Forms]![EditDeleteInvoice]![AddDogtoInv]![txtInvoiceNumber]")
= stInvoice
.Execute
End With
rs.Requery
Me.Recalc
rs2.Requery
Forms![EditDeleteInvoice]![AddDogtoInv].Requery
End Sub