Hi Maurice,
Ok, I've trying to avoid all the sordid details for simplification
purposes.
I actually have to forms here, frmLease, which has worked well for me for
years and does the lease payment calculations and gives me the TotalDue,
and
a new unbound popup form called frmRoll. On frmRoll I have an unbound
txtbox, txtSalePrice, which captures the SalePrice as it's default value
from
frmLease. I also have txtLicenseFee as an unbound textbox, with default
value of 0, and then the command button. The idea is to have and save the
original saleprice from frmLease for comparrison purposes.
Let's clear up some things first:
Forms!frmlease!SalePrice = Forms!frmlease!SalePrice +
((Forms!frmlease!TotalDue + Me.txtLicenseFee) - Forms!frmlease!SalePrice)
What you are doing here is calculating a saleprice and finally deducting
the
saleprice again from itself is that correct?
No, at this point SalePrice is already there. What I am doing is adding
the
the amounts from TotalDue and txtLicenseFee to the SalePrice.
Give me some numbers and of what you are testing with so I can try to
mimic
it.
Ok, SalePrice $33000
TotalDue $1109.90
First click of command button ads $1109.90 to SalePrice, changing it to
$34109.90, but then TotalDue changes to $1167.63, mostly because the first
payment changed (first payment is part of the 1109.90, and now part of the
$1167.63). Notice that the difference between the first TotalDue is
$57.73.
Clicking on the command button a 2nd time adds that amount to the
SalePrice.
The new difference is 1.71, and clicking on the command button again adds
that amount to the SalePrice. The new difference is .05, and clicking a
4th
time adds that amount to the SalePrice, and finally we have the Amount
that
has been added to the SalePrice equalling the TotalDue amount which is now
$1169.39. SalePrice has gone from the original amount of $33000 to
$34169.39.
What I need is to end up with the amount added to Sale = the final
TotalDue
amount.
Right now I see four fields
[SalePrice] - bound field? Yes
[txtSalePrice] - bound field? No, unbound and on popup
frmRoll
[TotalDue] - bound field? No, Calculated field on
frmLease
[LicenseFee] - Bound field? No, unbound and on popup
frmRoll
Maybe there is a better mathematical way to do this, but what I have been
is
first adding the TotalDue amount to the SalePrice, then checking how much
more then new TotalDue amount is and then adding the differnce to the
SalePrice, and then checking again for the new TotalDue amount, and then
adding the difference again to the SalePrice. Usually takes doing this
about
4 times to get the amount that is added to the SalePrice to = the TotalDue
amount. Again, remember, all I am trying to do is add the exact amount of
the Up front or TotalDue monies to the SalePrice so that the customer can
avoid coming up with any cash out of pocket.
I hope this explains it. Thanks so much for your help.
--
Gary in Michigan, USA
Maurice said:
Hmm, we will get there. Right now you are in the same situation as where
you
started from.
Let's clear up some things first:
Forms!frmlease!SalePrice = Forms!frmlease!SalePrice +
((Forms!frmlease!TotalDue + Me.txtLicenseFee) - Forms!frmlease!SalePrice)
What you are doing here is calculating a saleprice and finally deducting
the
saleprice again from itself is that correct?
Give me some numbers and of what you are testing with so I can try to
mimic
it.
Right now I see four fields
[SalePrice] - bound field?
[txtSalePrice] - bound field?
[TotalDue] - bound field?
[LicenseFee] - Bound field?
So give me an example with numbers in your fields at the start and what
the
outcome should be at the end..
--
Maurice Ausum
:
Maurice, your 6 count loop works, but I still have to click the command
button 4 times to get the figures synced, so that the amount added to
the
selling price equals the total due amount. It's like Access cannot
dynamically check the TotalDue field as it runs the loop to see if if
needs
to add more to the Sale Price.
--
Gary in Michigan, USA
:
Gary,
If no conditions are met you are ending up in an endless loop. That's
what
Graham and Marshall are pointing out to you.
if you want your loop to only run six times you could try:
dim iCount as integer
iCount=0
Do While Forms!frmlease!TotalDue + Me.txtLicenseFee <
Forms!frmlease!SalePrice -
Me.txtSalePrice
Forms!frmlease!SalePrice = Forms!frmlease!SalePrice +
((Forms!frmlease!TotalDue + Me.txtLicenseFee) -
Forms!frmlease!SalePrice)
icount=icount+1
DoEvents 'Necessary to free up other processes
if icount=6 then exit do
Loop
see of that get's you anywhere. Remember the posts from Graham and
Marshall
stating you rethink tour strategy (what if the next time it should
run for 8
times? you would be changing your code constantly).
btw you also have to do the proper error handling as well in this
situation...
hth
--
Maurice Ausum
:
Hmm, that apparently starts an endless loop. I modefied your code
slightly
by changing the < to <=, but still get lockup, with no change
SalePrice when
the code is executed. Is there a way to only have it loop 6 times?
--
Gary in Michigan, USA
:
Gary,
I see what you mean. Try putting this behind the click event of
your button:
While Not Forms!frmlease!TotalDue + Me.txtLicenseFee <
Forms!frmlease!SalePrice - Me.txtSalePrice
Forms!frmlease!SalePrice = Forms!frmlease!SalePrice +
((Forms!frmlease!TotalDue + Me.txtLicenseFee) -
Forms!frmlease!SalePrice)
Wend
That should do the trick for ya...
hth
--
Maurice Ausum
:
I decided maybe more explanation was required.
FrmLease calculates lease payments. Normally people pay
certain costs up
front, but some times I need to roll those costs in to the Sale
Price. When
I add to the Sale Price it changes the TotalDue. I need to run
the code
(recalculate) 4 times to make amount added to the Sale Price =
the TotalDue.
I hope this helps some kind soul make sense out of what I am
trying to do.
Thank you
--
Gary in Michigan, USA
:
Hello -Using Access 2003 I have the following code in the
click event of a
command button.
If Forms!frmlease!TotalDue + Me.txtLicenseFee <
Forms!frmlease!SalePrice -
Me.txtSalePrice Then
Forms!frmlease!SalePrice = Forms!frmlease!SalePrice +
((Forms!frmlease!TotalDue + Me.txtLicenseFee) -
Forms!frmlease!SalePrice)
End If
Basically I need the code to run several times until the
condition is met (a
loop?). I've tried several if then statements together but
it seems the
condition only gets checked once per click, as clicking
several times
achieves the result. I know this can be accomplished with
some sort of loop,
but I don't understand how to do it. Any help would be
greatly appreciated.
Gary in Michigan, USA