PC Review


Reply
Thread Tools Rate Thread

Calculating a text box

 
 
cornedbeef007-groups@yahoo.com.au
Guest
Posts: n/a
 
      22nd Jul 2010
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.
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      22nd Jul 2010
On Thu, 22 Jul 2010 05:48:42 -0700 (PDT), cornedbeef007-(E-Mail Removed)
wrote:

>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/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
cornedbeef007-groups@yahoo.com.au
Guest
Posts: n/a
 
      23rd Jul 2010
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".


 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      23rd Jul 2010
On Fri, 23 Jul 2010 04:47:39 -0700 (PDT), cornedbeef007-(E-Mail Removed)
wrote:

> 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.


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/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
cornedbeef007-groups@yahoo.com.au
Guest
Posts: n/a
 
      24th Jul 2010
>
> >If updating Total happened at Donation.LostFocus, you wouln't see the
> >total update.

>
> 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.
 
Reply With Quote
 
cornedbeef007-groups@yahoo.com.au
Guest
Posts: n/a
 
      24th Jul 2010
>
> 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.
 
Reply With Quote
 
Bob Quintal
Guest
Posts: n/a
 
      24th Jul 2010
cornedbeef007-(E-Mail Removed) wrote in
news:291bf4cc-768e-4d55-89ed-(E-Mail Removed)
:

>>
>> >If updating Total happened at Donation.LostFocus, you wouln't
>> >see the total update.

>>
>> 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.
>


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
 
Reply With Quote
 
Bob Quintal
Guest
Posts: n/a
 
      24th Jul 2010
cornedbeef007-(E-Mail Removed) wrote in
news:13abe1c7-c12f-4855-aeb6-(E-Mail Removed)
:

>>
>> 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.
>


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.

 
Reply With Quote
 
cornedbeef007-groups@yahoo.com.au
Guest
Posts: n/a
 
      24th Jul 2010
>
> 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.
 
Reply With Quote
 
Access Developer
Guest
Posts: n/a
 
      24th Jul 2010
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.

--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access


<cornedbeef007-(E-Mail Removed)> wrote in message
news:291bf4cc-768e-4d55-89ed-(E-Mail Removed)...
> >
>> >If updating Total happened at Donation.LostFocus, you wouln't see the
>> >total update.

>>
>> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating how big text is. UJ Microsoft C# .NET 2 12th Apr 2006 02:22 PM
calculating text =?Utf-8?B?Y2hlZXNld2l6ejc2?= Microsoft Access Queries 7 15th Mar 2006 02:54 PM
calculating a value in a text box Bob Wickham Microsoft Access Form Coding 1 28th Jan 2006 06:50 AM
calculating a value in a text box Bob Wickham Microsoft Access Form Coding 5 26th Jan 2006 02:54 AM
Calculating in text box speed Marco Simone Microsoft Access Getting Started 1 12th Feb 2004 06:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:55 AM.