SetFocus Issue


J

John G.

I'm tring to write a simple routine to automate a group's "paper 'n napkin"
bookkeeping. They have several revenue streams, coffee, copy machine,
ceramics, membership, etc. I'm setting the input up to match what they are
presently doing on paper (You know the group I'm talking about when you hear
them say "Well we've done it this way for the last 20 years..."). Enough
said.
In the situation below, they would first count the funds for the particular
item, in this case, one source of coffee income, and input the information
into a text box. Then they recount, separating out checks, cash, and coin
individually (see excuse above as to why I'm not fighting them). This is a
double check. At least I convinced them to let Excel do the math. Each of
the inputs, check, cash, and coin values, are running very similar
subroutines that total rows and columns on form and each with the exception
of the "coin" routine, see below, perform fine.

Private Sub txtCoffeeSubCoin_AfterUpdate()

txtCoffeeSubCoin.Value = Format(Val(txtCoffeeSubCoin.Value), _
"$#,##0.00") 'fomats value in current txtbox
txtCoffeeMainCoin.Value = Format(Val(Mid(txtCoffeeSubCoin.Value, 2)) + _
Val(Mid(txtBingoSubCoin.Value, 2)), "$#,##0.00") 'combines both
income sources onto main income line and formats
TotalsColCoin 'totals the coin count column
TotalsCoffeeRow 'totals the main income source line
CBBingoSub.SetFocus 'sets the focus to a checkbox that turns the
visibility of the next line item's txtboxes on

End Sub

My problem is with the SetFocus line. As mentioned, the other similar
routines seem to handle the setfocus OK, tho they are setting focus on the
next txtbox in order, but when the line in question is executed, the program
jumps back to the beginning of the subroutine and reruns itself, clearing the
entry. I've commented out the line and the routine finishes like it should

Any help is appreciated. JG
 
Ad

Advertisements

B

Bob Bridges

I could be wrong, but I think you're missing this only because
it's so obvious. The routine runs whenever txtCoffeeSubCoin is
updated, and the routine updates txtCoffeeSubCoin; so when it
sets the focus somewhere else Excel figures txtCoffeeSubCoin
is now officially updated and starts the txtCoffeeSubCoin_AfterUpdate
routine. Don't you think?
 
Ad

Advertisements

J

John G.

I see your point regarding the fact that the formating is again updating the
txtbox BUT...all the other "_AfterUpdate" routines in the Userform use the
identical format line (tho txtbox name specific) and they don't appear to
have any problem. Regarding the 2nd time the routine runs, it clears the
value (maybe because it's already formatted) and finishes with a setfocus
somewhere else then the checkbox that's specified.
 

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