+ Reply to Thread
Results 1 to 11 of 11

Form textbox number formatting

  1. #1
    Forum Contributor
    Join Date
    04-20-2017
    Location
    Iowa
    MS-Off Ver
    2007
    Posts
    212

    Form textbox number formatting

    Hello All,
    Never seen this before but if I enter 1 in a text box it displays as 0.999999.....

    If I enter 1.0 I get a Type Mismatch error related to the following lines of code.

    Please Login or Register  to view this content.
    This is just a conversion calculator I can keep open when working with the other parts of the workbook.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Form textbox number formatting


    Hi !

    Try using Val VBA function to convert the textbox value …

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Form textbox number formatting

    There is nothing in that code that changes the value of txtFeet so I suspect you have other change events that are altering txtFeet?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Form textbox number formatting


    See this demonstration :

    PHP Code: 
    Sub DemoCalculationPrecision()
        Const 
    F$ = "20.4 - 19.6"L$ = vbLf vbLf
        C
    @ = Evaluate(F)
        
    D# = Evaluate(F)
        
    S! = Evaluate(F)
        
    MsgBox Space(27) & "Calcul  :  " "Type :    (@)  Currency =  " _
               Space
    (15) & "(#)    Double =  " _
               Space
    (15) & "(!)        Single =  " SvbExclamation
    End Sub 
    So try using a Currency variable …

  5. #5
    Forum Contributor
    Join Date
    04-20-2017
    Location
    Iowa
    MS-Off Ver
    2007
    Posts
    212

    Re: Form textbox number formatting

    I need to get going now, but I will copy this to a blank workbook and attach it to a post later on.

    Thanks for the input both of you.

  6. #6
    Forum Contributor
    Join Date
    04-20-2017
    Location
    Iowa
    MS-Off Ver
    2007
    Posts
    212

    Re: Form textbox number formatting

    Here is a sample of the workbook and form.
    Attached Files Attached Files

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Form textbox number formatting

    The issue is indeed the interaction between the boxes. Feet (1) sets Inches (12), which is fine. Inches(12) sets feet again (1), which is also fine. Inches (12) then sets Yards to 0.333333333. That then triggers the Yard_Change, which sets Feet to Yards * 3, hence your 0.999999999 value. Simplest solution is probably to disable all the other change events when you change a specific box. Add this to the top of the form code module, after the Option Explicit line
    Please Login or Register  to view this content.
    Now amend all the Change events like this
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    04-20-2017
    Location
    Iowa
    MS-Off Ver
    2007
    Posts
    212

    Re: Form textbox number formatting

    Thank xl, that's what it needed.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Form textbox number formatting

    You're welcome. Don't forget to mark the thread Solved, please.

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Form textbox number formatting

    @ xlnitwit,

    Impressive my friend!

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Form textbox number formatting

    Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] User form not formatting textbox date/currency values
    By rob_h in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-23-2017, 07:52 AM
  2. [SOLVED] Alphnumeric formatting in textbox on a form
    By Andelousiano in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-30-2017, 12:10 PM
  3. Userform Textbox Number Formatting VBA
    By chriswathen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2016, 02:37 PM
  4. VBA Form Textbox formatting
    By solnajeff in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-08-2012, 12:27 PM
  5. Possible to have number formatting in TextBox?
    By Carlsbergen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2010, 08:50 AM
  6. TextBox Formatting on a Form
    By UKSteveH in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-07-2008, 03:51 AM
  7. TextBox number / date / time formatting?
    By scadaman29325 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2008, 11:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1