Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Format textbox on exit

I have the following:

Private Sub tbAnnualInterest_Exit(ByVal Cancel As
msforms.ReturnBoolean)

tbAnnualInterest = Format(tbAnnualInterest / 100, "0.0000%")

End Sub


which works fine the first time a value (a percentage entered as 4.9
vs. .049) is entered into the textbox. However, if the textbox is
entered and exited without entering a new value, I get a Type mismatch
error. I've tried using various combinations of Val and/or CStr and
anything else I thought might be useful.

Any suggestions, as always, are greatly appreciated.

TIA
Mike

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Format textbox on exit

Mike,

Don't do it. Add a button to accept the value and format it

Private Sub cmdAnnualInterest_Click()
tbAnnualInterest.Text = Format(tbAnnualInterest.Text / 100, "0.0000%")
End Sub

and just tab back in if not okay.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Michael Malinsky" wrote in message
oups.com...
I have the following:

Private Sub tbAnnualInterest_Exit(ByVal Cancel As
msforms.ReturnBoolean)

tbAnnualInterest = Format(tbAnnualInterest / 100, "0.0000%")

End Sub


which works fine the first time a value (a percentage entered as 4.9
vs. .049) is entered into the textbox. However, if the textbox is
entered and exited without entering a new value, I get a Type mismatch
error. I've tried using various combinations of Val and/or CStr and
anything else I thought might be useful.

Any suggestions, as always, are greatly appreciated.

TIA
Mike



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Format textbox on exit

Bob,

I played with it for a while and determined that tacking on the "%"
like I originally did was the problem. So I modified my original code
and added an Enter event. The revised code is as follows:

Private Sub UserForm_Initialize

tbAnnualInterest = Format(0#, "0.0000%")

End Sub
-------
Private Sub tbAnnualInterest_Enter()

tbAnnualInterest = Format(Format(tbAnnualInterest, "0.0000") * 100,
"0.0000")

End Sub
-------
Private Sub tbAnnualInterest_Exit(ByVal Cancel As
msforms.ReturnBoolean)

tbAnnualInterest = Format(tbAnnualInterest, "0.0000") & "%"

End Sub
-------

I have a "nested" format statement in my Enter event, but it seems to
do the trick. I don't forsee any problems doing it this way.

Any thoughts?

Thanks,
Mike

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Format textbox on exit

Mike,

I played around with this, and it works well doesn't it? Couldn't see any
real problems. I just didn't like the textbox being loaded with 0.0000, but
that may just be me.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Michael Malinsky" wrote in message
ups.com...
Bob,

I played with it for a while and determined that tacking on the "%"
like I originally did was the problem. So I modified my original code
and added an Enter event. The revised code is as follows:

Private Sub UserForm_Initialize

tbAnnualInterest = Format(0#, "0.0000%")

End Sub
-------
Private Sub tbAnnualInterest_Enter()

tbAnnualInterest = Format(Format(tbAnnualInterest, "0.0000") * 100,
"0.0000")

End Sub
-------
Private Sub tbAnnualInterest_Exit(ByVal Cancel As
msforms.ReturnBoolean)

tbAnnualInterest = Format(tbAnnualInterest, "0.0000") & "%"

End Sub
-------

I have a "nested" format statement in my Enter event, but it seems to
do the trick. I don't forsee any problems doing it this way.

Any thoughts?

Thanks,
Mike



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Format textbox on exit

Bob,

That's the best I came up with at this point. It seems that if I leave
the "%" sign there, then the value automatically gets converted to a
percentage (i.e., 4.9% becomes 0.049). Then when you repeatedly enter
and exit the textbox, the number kept getting divided by 100 (0.049,
0.00049, etc.). The only time the textbox contains 0.0000 is when it
is entered. The rest of the time it has the "%" on the end. I'll just
have to specify on the userform exactly what needs entered.

Thanks.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Private Textbox Exit Sub question... [email protected] Excel Worksheet Functions 14 March 1st 07 03:58 AM
How To Get An Event To Run When I Exit A TextBox Minitman[_4_] Excel Programming 7 October 22nd 04 11:27 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM
Format Textbox as % Todd Huttenstine[_2_] Excel Programming 2 December 15th 03 12:07 AM
MSForms.TextBox Exit event isn't available in Excel class mosule lacos Excel Programming 2 December 12th 03 10:12 AM


All times are GMT +1. The time now is 11:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"