Results 1 to 13 of 13
  1. #1
    bmonz4 is offline Novice
    Windows 11 Office 365
    Join Date
    Jun 2024
    Posts
    4

    trying to code a number keypad, decimal point does not work

    Hi all! unsure if this is the correct place to post this, if not sorry!

    I am new to using Access and trying to create a number keypad to be used in Access 365. All the number, as well as the "clear," buttons work, but I cannot get a decimal point to get inserted into the field for the life of me. I was wondering if someone can look at this code I used and try to fix it for me.

    Thanks!

    Private Sub NumDecimal_Click()
    If Not CurrentTextBox Is Nothing Then
    If InStr(CurrentTextBox.Value, ".") = 0 Then
    CurrentTextBox.Value = CurrentTextBox.Value & "."
    End If
    End If
    End Sub




    for reference, here is the "1" digit code, that works fine and basically works with all my other digits

    Private Sub Num1_Click()
    If Not CurrentTextBox Is Nothing Then
    CurrentTextBox.Value = CurrentTextBox.Value & "1"
    End If
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    What do you mean by 'field'? A table field or an unbound textbox?

    Display of decimal point followed by zeros is a format setting for numeric values. If you are entering a string, that is different issue.

    Any help in https://www.access-programmers.co.uk...yboard.156617/
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bmonz4 is offline Novice
    Windows 11 Office 365
    Join Date
    Jun 2024
    Posts
    4
    It is a text box, or several text boxes that I am using. Again, all the number buttons and clear button works on all the text boxes, except for this darn decimal point!

    When I use the decimal point on my regular keyboard, it inserts a decimal.. if that means anything as well

    Thanks for the quick response!

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Perhaps the key is broken? Does it work in other applications?
    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
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    Is the 'field' defined as an integer or long integer? By definition integers are whole numbers and do not allow decimal entry.

  6. #6
    bmonz4 is offline Novice
    Windows 11 Office 365
    Join Date
    Jun 2024
    Posts
    4
    I do not think it is broken. I tried making a new button with a different name and still same issue

    I have the field formatted as "Currency" with 2 decimal places

    The a decimal point DOES get inserted into the selected textbox when I use my keyboard and everything functions correctly, the decimal DOES NOT get inserted when I use the number keypad I made, which is extremely frustrating.. but again, all numbers 0-9 work as well as the clear button on all the selected textboxes

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,258
    Upload your DB with just enought to replicate the issue.
    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
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    This works fine for me.
    Here's the form (unbound)

    Click image for larger version. 

Name:	calc.png 
Views:	33 
Size:	6.9 KB 
ID:	51834

    Here's the VBA

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub CE_Click()
        CurrentTextBox = Null
    End Sub
    
    
    Private Sub Num0_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "0"
        End If
    End Sub
    
    
    Private Sub Num1_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "1"
        End If
    End Sub
    Private Sub Num2_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "2"
        End If
    End Sub
    Private Sub Num3_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "3"
        End If
    End Sub
    Private Sub Num4_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "4"
        End If
    End Sub
    Private Sub Num5_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "5"
        End If
    End Sub
    Private Sub Num6_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "6"
        End If
    End Sub
    Private Sub Num7_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "7"
        End If
    End Sub
    Private Sub Num8_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "8"
        End If
    End Sub
    Private Sub Num9_Click()
        If Not CurrentTextBox Is Nothing Then
            CurrentTextBox.Value = CurrentTextBox.Value & "9"
        End If
    End Sub
    
    'NOTE: fixes bug in your published code which will not allow leading decimal point
    'Unclear if this is your original complaint
    Private Sub NumDecimal_Click()
        If CurrentTextBox & "" = "" Then
            CurrentTextBox = "0."
        Else
            If InStr(CurrentTextBox.Value, ".") = 0 Then
                CurrentTextBox.Value = CurrentTextBox.Value & "."
            End If
        End If
    End Sub
    Last edited by davegri; 06-02-2024 at 03:05 PM. Reason: added note

  9. #9
    bmonz4 is offline Novice
    Windows 11 Office 365
    Join Date
    Jun 2024
    Posts
    4
    It actually does work in an unbound textbox for me, but I need to have it function on a bound textbox… is there a big difference in how I would code it?

    I double checked format, decimal, field size, and data type in tables and forms sections, and I can’t find what’s wrong

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Again, perhaps you should provide your file.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    I double checked format, decimal, field size, and data type in tables and forms sections,
    The form is manipulating a string, so the table field should be short text.
    In the form, the format property should be blank
    The data tab text format property should be 'plain text'
    Last edited by davegri; 06-04-2024 at 11:22 PM. Reason: Added DB

  12. #12
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,700
    I see a couple of problems with having the solution I provided in post#11 using a bound form.
    For example, when the form loads, it will always show the value of the first record in the table. I suspect you want it to show nothing.
    you've provided no context for the form's existence, so it's unknown how the form will know which record in the table to update.

    You have been asked twice to provide your database and have not responded. If you had done so, I think your problem would have been much closer to resolution by now.
    The main reason I put people on my ignore list is because they ignore requests for vital information.

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,258
    Quote Originally Posted by bmonz4 View Post
    It actually does work in an unbound textbox for me, but I need to have it function on a bound textbox… is there a big difference in how I would code it?

    I double checked format, decimal, field size, and data type in tables and forms sections, and I can’t find what’s wrong
    Update the bound control from the unbound control?
    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. Leading Zero and Decimal Point
    By didiomm in forum Programming
    Replies: 13
    Last Post: 09-07-2016, 01:46 PM
  2. Too many digits after decimal point!
    By euphonium01 in forum Queries
    Replies: 3
    Last Post: 02-18-2016, 05:54 AM
  3. Replies: 7
    Last Post: 02-27-2015, 09:21 AM
  4. Delete Zero after decimal point!
    By cuongmyh in forum Forms
    Replies: 1
    Last Post: 02-26-2015, 07:06 AM
  5. Convert decimal comma to decimal point
    By Hans Karlsson in forum Programming
    Replies: 3
    Last Post: 06-30-2014, 01:56 PM

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