OK, you set CurrNumbShares, but you don't use it later. Instead, you re-retrieve it from the form.

Here's the way to solve the problem algebraically: assume you have a ShareCounter that works! Usually, in algebra, we call that x, but we can call it anything we want. Let's call it SharesToBuy.

The restriction on SharesToBuy comes from wanting the following to be true, correct?

TargetCPS = (NewInvestment + CurrInvestment) / NewNumShares

We also know that

NewNumShares = Forms!SalesScheduleFrm!StockShares + SharesToBuy

NewInvestment = (Forms!SalesScheduleFrm!Text115 * SharesToBuy)

even though we don't yet know what SharesToBuy is (it's the x that algebra is always looking for!) We can combine the three equations into a single equation where we know everything, except SharesToBuy, because algebra can solve that equation for SharesToBuy:

TargetCPS = ((Forms!SalesScheduleFrm!Text115 * SharesToBuy) + CurrInvestment) / (Forms!SalesScheduleFrm!StockShares + SharesToBuy)

Solving that equation algrbraically for SharesToBuy, we get (which can replace your program, except where you set the values CurrInvestment and TargetCPS, or you could include them directly):

SharesToBuy = (CurrInvestment - TargetCPS * Forms!SalesScheduleFrm!StockShares) / (TargetCPS - Forms!SalesScheduleFrm!Text115)

SharesToBuy = ($3000 - $5 * 1000) / ($5 - $10)

SharesToBuy = 400

## Bookmarks