Deleting rows in subforms

G

Guest

Hi

Can anyone help me with this.

I have a subform where I enter items which are orderlines, the row contains
a field called subtotal which adds up the total of that row, a simple sum
where it looks at no. of items ordered and multiplys that by the price to
give a subtotal for the row.
Outside of this subform I have a field which gives the total value of the
subtotals so giving at the end a total order value.

Problem is, if user deletes a row off the subform, the total value does not
change and I would like it to update the value but not sure how to do this.

Please reply asap if anyone out there can help me on this one... much
appreciated.

Thanks in advance.
 
G

Guest

Not sure how to do this the code I have in the subform is

Private Sub quantity_LostFocus()
Forms!order!txtTotal = Forms!order!txtTotal + txtSubTotal
End Sub

so how do I tell it to deduct the values that were in the rows that were
deleted as it hadnt stored the values anywhere to look them up to know what
to delete.

Need a little more assistance than just add code to the forms Delete event,
I am not experienced in access and code.

Thanks
 
T

Tom Ellison

Dear Saj:

There's more to the problem than just the deletion of a row. There are
three things that change the state of a database: insertions, deletions,
and updates. All 3 of these can change your total. These changes to the
database could be made by any user, not just the one operating a given
instance of the database.

There are events that can update your total for each of these 3 cases when
it is the currently opened form that is involved. When another user does
something like this, there is no direct solution. There are two solutions
that may be applicable:

1. Have a timer that periodically causes the total to be recalculated.

2. Put a button on the form so the user can check for changes.

These two solutions are not mutually exclusive. You could do both.

In some cases, it is not necessary to show the user the updated total. The
button is often all that is needed. If the user actually cares to be
certain he has the latest total, he can update his screen, not only the
totals, but the current version of the rows that result in that total.
Would it not be important that the rows shown on the screen actually add up
to the total shown? Just updating the total would not be sufficient if it
is another user who has posted changes to the rows making up that total.

There's a lot to think about here. Thinking may be your next step.

Tom Ellison
 
G

Guest

The delete event occurs befoe the actual deletion is done. IF txtSubTotal is
the control in the subform that contains the sub total for the row, then
using the code you posted as a basis, it would probably be:

Forms!order!txtTotal = Forms!order!txtTotal - txtSubTotal

I notice you are referenceing the control txtSubTotal without qualifiying
it. It is always better to include a reference to the form it is on, even if
it is the current form.
 
G

Guest

I have looked at it and have implemented the delete as suggested by Klatuu
and this works fine, but as said by Tom updates need to be looked at.

When user types value in it adds to the field, when they go back and delete
a row or rows it deletes the value in the field, but if I go back to the row
and key in another value, it adds on that new value without deducting the
previous one so if it was 1 item at £15 and I change to 2 items the total
will show a total for 3 items not two.

I'm hoping there is a simpler solution and not one too complicated as I am
not an experienced programmer or access person.

Is there anything I can do to this field to say if the value changes, deduct
the previous value before storing the new value, then add the new value, does
that make any sense... hope so...

If so would appreciate some help... thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top