Results 1 to 10 of 10
  1. #1
    budgie is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2015
    Location
    Wollongong NSW Australia
    Posts
    3

    Number fields


    I am looking for a way to have a decimal point inserted automatically before the last two digits of whatever I enter, e.g. entering 123 would result in 1.23 being stored. In Excel this was called "Accountant's Keypad" I believe.
    I have tried various number types and fixed decimals, and input masks, but can't make it work.
    My version of Access is from the Office 2000 suite.

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You could simply divide the entered value by 100?
    But What happens if you really only want to enter 1.00

    You would have to type 100, instead of simply 1 , so I'm not sure what the saving is?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    budgie is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2015
    Location
    Wollongong NSW Australia
    Posts
    3
    The saving is that if you're entering a lot of dollar and cent values you don't have to use the decimal point key. That adds up to a lot of keystrokes after a time. If entering a whole dollar amount you can terminate with a "." instead of the two additional zeroes.
    BTW setting the field as "currency" will not provide the function I require, at least not in my version of Access.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Jeez,
    I am not the fastest typist in the world, but even I would not even bother with that 'shortcut'?
    As mentioned you could divide by 100, after some basic checks?

    This should get you started.
    Code:
    Private Sub ToleranceValue_LostFocus()
    If InStr(1, Me.ToleranceValue, ".") > 0 Then
        Me.ToleranceValue = Val(CStr(Me.ToleranceValue) & ".00")
    End If
    Me.ToleranceValue = Me.ToleranceValue / 100
    End Sub
    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

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You point about pressing the decimal point when you need to is what makes this difficult, or at least harder.
    If you use a function you can detect if it contains a decimal point and if so not process it.
    if it doesn't have a decimal point then divide by 100.

    This is aircode but something like
    Code:
    Function fnDecmalEntry(dNumber As Currency) As Currency
    
    
        
        If InStr(1, CStr(dNumber), ".") > 0 Or dNumber = 0 Then
            fnDecmalEntry = dNumber
            Exit Function
        End If
                
        fnDecmalEntry = dNumber / 100
    
    
    
    
    End Function
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Shouldn't be too hard to code something in the BeforeUpdate event for the form control, but that's the limitation (must use a form).
    Logic being "if ends with . just remove it, otherwise divide by 100. Not sure, but perhaps you don't have to remove the trailing . Access just might drop it anyway.

    EDIT - just tried leaving the . at the end directly in a table - it was just dropped. So even simpler than the posted code?

    If Right([fieldnamehere],1) = "." then simply divide?

    EDIT 2 - works if it is a whole number only, so not so simple I guess.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by Micron View Post
    Shouldn't be too hard to code something in the BeforeUpdate event for the form control, but that's the limitation (must use a form).
    Logic being "if ends with . just remove it, otherwise divide by 100. Not sure, but perhaps you don't have to remove the trailing . Access just might drop it anyway.

    EDIT - just tried leaving the . at the end directly in a table - it was just dropped. So even simpler than the posted code?

    If Right([fieldnamehere],1) = "." then simply divide?
    Yes, this appears to work
    Code:
    If Not Right(Me.ToleranceValue, 1) = "." Then
        Me.ToleranceValue = Me.ToleranceValue / 100
    End If
    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

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    I added an edit. Does it work with numbers that are not whole numbers? Does the data type matter (integer, decimal, currency, long) I wonder?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Hmm my aircode doesn't actually work, unless the input is really a string.
    If you enter 10.0 as a number access strips the .0 from it during evaluation, so you end up with 0.1 as a result.

    I'll revisit it later.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    I used double for the table and currency format for the form?
    O/P will have to do some testing?
    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

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 03-27-2020, 09:46 AM
  2. Replies: 10
    Last Post: 04-01-2018, 07:45 AM
  3. Trying to reduce number of fields
    By dallin in forum Database Design
    Replies: 1
    Last Post: 09-09-2014, 11:32 PM
  4. Summation of N Number of fields
    By deepanadhi in forum Queries
    Replies: 5
    Last Post: 06-07-2012, 10:48 PM
  5. Number of Fields Exceeded
    By tsn.s in forum Database Design
    Replies: 2
    Last Post: 12-06-2011, 05:35 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