Calculating a text box

  • Thread starter Thread starter cornedbeef007-groups
  • Start date Start date
C

cornedbeef007-groups

I have a form to record payments for dog show entries.
I have an Exhibitor table that holds exhibitor details, and
Exhibitor_id
I have a Payment table that holds Exhibitor_id, and payment details.

My form has a text box for "Entry" amount, and a text box for
"donation" amount.
I want to have a "Total" amount field show on the form, so that as
entry is made into either the "Entry" or "Donation" text boxes, the
"Total" box shows the total of the other two boxes.
My Total box is a Label control

I currently have an On Update event on each of my two inputs, which
runs this code.
Me.Total.Caption = "$" & Me.Entry.Value + Me.Donation.Value

I have tried the OnChange event, OnKeyUp event, OnLostFocus event, but
none of them result in the Total updating as I type.

What event do I need to use to make it update on each keystroke, or is
there some other way to display the total amount?

BTW, the underlying Payment table doesn't hold a Total field. I
calculate it by adding the individual amounts.
 
I have a form to record payments for dog show entries.
I have an Exhibitor table that holds exhibitor details, and
Exhibitor_id
I have a Payment table that holds Exhibitor_id, and payment details.

My form has a text box for "Entry" amount, and a text box for
"donation" amount.
I want to have a "Total" amount field show on the form, so that as
entry is made into either the "Entry" or "Donation" text boxes, the
"Total" box shows the total of the other two boxes.
My Total box is a Label control

I currently have an On Update event on each of my two inputs, which
runs this code.
Me.Total.Caption = "$" & Me.Entry.Value + Me.Donation.Value

I have tried the OnChange event, OnKeyUp event, OnLostFocus event, but
none of them result in the Total updating as I type.

What event do I need to use to make it update on each keystroke, or is
there some other way to display the total amount?

BTW, the underlying Payment table doesn't hold a Total field. I
calculate it by adding the individual amounts.

I'm not sure what you're saying. If you're entering $125 into the Entry
textbox, do you really need the Total box to show

$

then

$1

the

$12

and so on? Do you want it to show

$12510

if the user pays $125 Entry and a $10 donation (since you're building it up as
a text string rather than a number that's just what you'll get).

Keystrokes enter text strings. Arithmetic operators such as + work on Numbers,
not text strings. Why the insistance that this happen on every keystroke,
rather than as soon as the value has been entered?
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
Why the insistance that this happen on every keystroke,
rather than as soon as the value has been entered?

Detecting the end of entry is my problem I suppose. That's why I think
I need to update at each keystroke.

Working your way down the form with details like account name, bsb
number, cheque number, entry amount, donation amount.

You could update Total when "entry" loses focus, but after entering
"donation" amount, you would (probably) click the "Save" button to
save the record.
If updating Total happened at Donation.LostFocus, you wouln't see the
total update.

I'd like it to update as each figure is typed, if I can.

The input boxes, and the underlying table fields are formated
Currency, with a default of 0. The boxes initially show "$0.00".
 
Why the insistance that this happen on every keystroke,

Detecting the end of entry is my problem I suppose.

The control's AfterUpdate fires at the end of the entry. That's what it's FOR.
That's why I think
I need to update at each keystroke.

Working your way down the form with details like account name, bsb
number, cheque number, entry amount, donation amount.

You could update Total when "entry" loses focus, but after entering
"donation" amount, you would (probably) click the "Save" button to
save the record.

Or just move to the new record, and let Access save it for you automatically.
You don't *need* a Save button. You can certainly include one, but it's belt
and suspenders!
If updating Total happened at Donation.LostFocus, you wouln't see the
total update.

Ummm... and why not?
I'd like it to update as each figure is typed, if I can.
The input boxes, and the underlying table fields are formated
Currency, with a default of 0. The boxes initially show "$0.00".

The format is irrelevant.

If you insist, note that the Change event fires at every keystroke. The
textbox's Value property is not changed until the user moves to another
control, but its Text property will be current. The sum will, of course, be
wrong - if you've typed "12" then it will add 12, even if the value being
entered is 125 - but if that's what you want:

Private Sub Donation_Change()
Me!txtTotal = Val(Me!Entry) + Val(Me!Donation.Text)
End Sub

Note that this uses the Text property, which is a String, so you need the
Val() to convert it to a number (an incorrect number) which can be added.
You'll need similar code in the Entry textbox's change event.

--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
Ummm... and why not?

With AfterUpdate, How would it know, having typed "10" whether I was
finished, or was going to type another "0" like this 100

LostFocus occurs when you leave the control, then you don't
necessarily leave the last input box "donation" before saving the
record.
Total won't updated to be seen.

I'd like to confirm that the values for "entry" and "donation" add up
to the total value written on the cheque.
 
Or just move to the new record, and let Access save it for you automatically.
You don't *need* a Save button. You can certainly include one, but it's belt
and suspenders!

There is no "next record" to move to.

My input method is to have an "Exhibitor" form, where you can select
an existing exhibitor from a combobox, or add a new exhibitor.When you
select the exhibitor, their address details show for editing if needs
be, or confirmation that you have the correct "Smith" exhibitor among
all the"Smith"s.
You can then access that exhibitor's dogs, to update any details for
existing dogs, or add a new dog top their list.

You can then enter their dog(s) into a show by class.
Then you need to record payment for the entries, so there is usually
one payment cheque for all their entries, and maybe a catalogue, and
maybe a donation, and maybe tickets for the presentation dinner.
On the Exhibitor form, once an exhibitor has been selected, then
"Dogs", "Entry" and "Payment" buttons all appear, to open forms which
are supplied with the exhibitor_id, to label the dogs/entries/payments
as belonging to this exhibitor by foreign key in the respective "dog",
"show" and "payment" tables,

That's why I need a "Save" button, to store a record, and give
confirmation that the record has indeed been saved..
If you just filled in the form, and closed the form, you might wonder
if the details were in fact saved.

This application will be used people who really shouldn't own a
computer. I wan't to make it as "break proof" as possible.
 
(e-mail address removed) wrote in
:
With AfterUpdate, How would it know, having typed "10" whether I
was finished, or was going to type another "0" like this 100

LostFocus occurs when you leave the control, then you don't
necessarily leave the last input box "donation" before saving the
record.
Total won't updated to be seen.

I'd like to confirm that the values for "entry" and "donation" add
up to the total value written on the cheque.

Then use an unbound Total textbox to hold yhe value of the cheque..

Use the form's Before_Update event to test
If me!Total <> me.Entry + Me.Donation then
cancel = true
msgbox "Entry and Donation Values must equal Total", vbOKOnly
end if
 
(e-mail address removed) wrote in
:
There is no "next record" to move to.

My input method is to have an "Exhibitor" form, where you can
select an existing exhibitor from a combobox, or add a new
exhibitor.When you select the exhibitor, their address details
show for editing if needs be, or confirmation that you have the
correct "Smith" exhibitor among all the"Smith"s.
You can then access that exhibitor's dogs, to update any details
for existing dogs, or add a new dog top their list.

You can then enter their dog(s) into a show by class.
Then you need to record payment for the entries, so there is
usually one payment cheque for all their entries, and maybe a
catalogue, and maybe a donation, and maybe tickets for the
presentation dinner. On the Exhibitor form, once an exhibitor has
been selected, then "Dogs", "Entry" and "Payment" buttons all
appear, to open forms which are supplied with the exhibitor_id, to
label the dogs/entries/payments as belonging to this exhibitor by
foreign key in the respective "dog", "show" and "payment" tables,

That's why I need a "Save" button, to store a record, and give
confirmation that the record has indeed been saved..
If you just filled in the form, and closed the form, you might
wonder if the details were in fact saved.

This application will be used people who really shouldn't own a
computer. I wan't to make it as "break proof" as possible.

Then definitely do not ask them to visually validate the number on
the cheque with the calculated value on the form, Make them type in
the amount from the cheque to an unbound field, validate against the
other entries, and cancel the save if the amounts do not agree.
 
Then definitely do not ask them to visually validate the number on
the cheque with the calculated value on the form, Make them type in
the amount from the cheque to an unbound field, validate against the
other entries, and cancel the save if the amounts do not agree.

Great idea!

Another set of eyes sees a different solution to the same problem.

Thanks.
 
Check Help on AfterUpdate... it, too, does not fire until you move off the
control. It is more reliable than LostFocus -- which can fire even though no
change was made, for example, just tab throug the control on the way to
another. Perhaps you are thinking of the OnChange event which fires after
each keystroke in the control.
 
Back
Top