Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53

    How do I have text go from right to left in textbox

    I have searched and searched and searched for HOURS and every time I think there is a solution, it still doesn't worked. Most of the time I have attempted to use the Input Mask property for the textbox, but that has not worked.



    I am trying to do is this. As a person inputs an amount (representing dollars and cents) into the text box I want it to be like a calculator display with the last two digits always being "cents". So if I typed "100" it would "$1.00". I don't want to have to use decimal points in the process but I also would like, if possible, if the decimal key is pressed, the previous numbers would be dollars. In other words if I typed "500." it would be "$500.00".

    I don't like the idea of using any of the on key events because I have never been successful when other keys like the backspace or delete key is entered to delete a number, or using the mouse to move the cursor in the text box.

    Any suggestions would be greatly appreciated. thanks.

    Ken L

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Set the format property of the textbox to Currency

    EDIT
    If the textbox is bound to a field in a table, then set the fields data type as currency as well.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    Tried that . It only formats it after the enter key is entered, not during, and it doesn't changed the direction from Right to Left for that text box

    Another way of describing how I would like to have it behave is as follows

    For a result of 54.32.

    5 Key pressed Text Box shows .05
    4 Key pressed Text Box shows .54
    3 Key Pressed Text Box shows 5.43
    2 Key Pressed Text Box shows 54.32

    Now in a different scenario where its 123.00

    1 Key Pressed Text Box shows .01
    2 Key Pressed Text Box shows .12
    3 Key Pressed Text Box shows 1.23
    . Key Pressed Text Box Shows 123.
    0 Key Pressed Text Box Shows 123.0
    0 Key Pressed Text Box Shows 123.00

    Thanks

    Ken L

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Quote Originally Posted by kleaverjr View Post
    Tried that . It only formats it after the enter key is entered, not during, and it doesn't changed the direction from Right to Left for that text box

    Another way of describing how I would like to have it behave is as follows

    For a result of 54.32.

    5 Key pressed Text Box shows .05
    4 Key pressed Text Box shows .54
    3 Key Pressed Text Box shows 5.43
    2 Key Pressed Text Box shows 54.32

    Now in a different scenario where its 123.00

    1 Key Pressed Text Box shows .01
    2 Key Pressed Text Box shows .12
    3 Key Pressed Text Box shows 1.23
    . Key Pressed Text Box Shows 123.
    0 Key Pressed Text Box Shows 123.0
    0 Key Pressed Text Box Shows 123.00

    Thanks

    Ken L
    What result do you want with the first scenario if the next key is another number eg "3"
    and what result do you want if the next key is a second period eg "."
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    I think you are going to have to roll your own formatting with a KeyPress event?
    Going from 1.23 to 123 just because you have pressed the . key is counter intuitive?
    What happens if you press it again?

    Seems a lot of work, just to have something work non standard?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You could use OnChange event of the textbox but IMO it is not possible without a key press event (or did you mean you don't want to use SendKeys, which is not the same thing). However, you'd have to map out what happens for certain batches of keys; more so than what I show here, such as not allowing 0123.

    Then there is the matter of what to do if decimal key is pushed and what to do if you want thousands separators. This might get you started

    Code:
    Private Sub myTextbox_KeyUp(KeyCode As Integer, Shift As Integer)
    
    MsgBox KeyCode 'disable after testing
    Select Case KeyCode
       Case 43, 27, 10, 13, 8
          'do nothing
       Case 48 To 57
          Me.myTextbox = Me.myTextbox & Chr(KeyCode)
       Case 97 To 105
          Me.myTextbox = Me.myTextbox & Chr(KeyCode - 48)
    End Select
    
    End Sub
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    The reason I'm hesitant to use a keypress event, is the first character is "captured" and doesn't display. I could do a VARIABLE = KEYCODE (or KEYASCII) and then STRINGOFCHARACTERS = STRINGOFCHACHTERS + VARIABLE, but the backspace and the delete key's foul things up. And even if I got that to work, what happens if the user (since I won't be the only one using this program) takes the mouse and moves the cursor within the textbox, then that FORMULA won't work. I could do without the use of the decimal point and for 123.00 the user will just always need to type 12300 like every cash register system I ever used worked, but that still leaves the other issues.

    What I don't understand is what is the ! (exclamation point) do for an input mask. (i.e. !999.99) It says on the Microsoft Help web pages that it causes it to change to go from the Right to Left, but it does nothing.

    Thanks all.

    Ken L

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    right to left applies when you choose a language where that is the way the data would be entered naturally for that language

    agree with others seems a lot of work to apply a non standard way of doing things. But if you really want to go that route, use the control change event. That will pick up any change whether done by key or mouse.

    change event only works whilst the control has the focus and you refer to the control text property.

    perhaps something like

    mycontrol.text=format(replace(mycontrol.text,"."," ")/100,"#.00")
    mycontrol.selStart=len(mycontrol.text)

    You probably need to set the control text align property to right as well

    which should meet your right to left requirement but doesn't solve the problem if the user has used the mouse to select a middle point to make a change- you would need to capture the seltart value with the mouse up event, store in in a form variable and use that in the change event.

    This is not something I want to get into a debate about, so the above is a suggestion for you to try out and no doubt modify to meet all the potential requirements of your app

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    the first character is "captured" and doesn't display.
    Well, what I posted worked albeit with limited testing. If I entered 1234, those characters were added from right to left so I have no idea what that means, I'm afraid.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    Whenever I used the Key Press event the last character entered never shows up when i used that event. I do not know why

    Ken L.

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You could post that code? I didn't use keypress event as it's supposedly deprecated. Also, AFAIK, it's only for characters that can be represented thus is likely useless for trapping delete, enter, backspace and the like. That may or may not be relevant to this challenge but I don't know.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    The On Change appears to be working. The issue with the Key Press event might have had to do with the fact that it was with the use of a barcode scanner and the first digit would never show up. I found a different way of handling that so never returned to the Key Press event.

    Right now everything is working, however a new "issue" popped up and would like to prevent it from even possibly happening because as I said before, I won't be the only one using the software, and having it "crash" would not be a good thing.

    If the INS key is pressed accidentally and starts overwriting numbers it messes up the formatting. Long story short, the easiest solution would be to somehow when this program is running the INS Key is totally disabled and/or if the INS Key is set to OVR Mode to turn it off. From what I have come up with it can be done in Word, but the VBA code to turn it off in Word does not work with Access. Any ideas. I KNOW the solution is to just press the INS Key again, but if the user presses it and starts typing info into the textbox, because of the complexity of the code as edits to the number are allowed that have .selstart NOT at the end, it will corrupt the entry crashing the program. Thanks. Agaom

    Ken L

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Use word automation to disable/enable it then
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    kleaverjr is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2022
    Posts
    53
    I'm slightly confused. How can Word effect a Form Textbox in Access?

    Ken L.

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    I am talking about disabling the INS key? -(
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-15-2020, 10:43 AM
  2. Replies: 8
    Last Post: 08-30-2019, 12:02 PM
  3. Text Field removal of numbers ? Left(?
    By d9pierce1 in forum Queries
    Replies: 3
    Last Post: 03-26-2019, 07:34 PM
  4. Replies: 3
    Last Post: 02-01-2018, 03:10 AM
  5. Replies: 6
    Last Post: 02-26-2016, 05:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums