Results 1 to 15 of 15
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    310

    Input mask on a form

    Hi,
    I have a numeric field: Data type : long integer, required, Indexd (duplicates OK)
    I want to have an input mask on a form that seperates the values with a dot (.)

    Sample:
    Without input mask ======with input mask
    125687 ================125. 687
    12456 ================= 124.56
    548976598 ============== 548.976.598
    12 =================== 12 (It is not important if it shows the (.) like: 12 . .
    24001 ================= 240.01
    2411 ================== 241.1

    I also need to do sorting for this field
    240.01 is sorted before 241.1 as an example



    How can this be done?

    Khalil

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Khalil

    This should work:- 999\ 999\ 999;0;_

  3. #3
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    Sorry, it gives the follwoing: 26 271 instead of 262.71

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    An input mask for a number field doesn't make sense. Format and DecimalPlaces properties are for controlling display of number data. Type what you want in InputMask property but data entry will error for number field. Use the InputMask builder and it will tell you "only works for Text or Date field types".

    Even if you do apply InputMask on the field that already has data, it won't actually change the stored value. Sorting and filtering will still see the actual data.

    Even though it is in number field, data is not numeric in nature, it is textual. One value looks like an SSN (9 digits). In a number field 2411 will sort before 24001. If you want 24001 before 2411, then must be a text field and 24001 will sort before 2411 alphabetically.
    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.

  5. #5
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    310
    Hi June7
    OK. So I have to use the Format and Decimal places in the table design view to have the following:
    548.976.598 or 240.01 0r 241.1
    Number data has only one decimal point so it will work for 241.1 or 240.01 and since 240.01 as a number is less than 241.1 (as regular numbers) then it will sort before
    In this case my data in the table will show with the decimal point.
    How can I deal with values like 548.976.598 ?

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Another option is to just store as a number so there are no sorting issues, then hide that field on the form/report and show a "formatted" version of it in another control instead.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    I edited my previous post probably after you read. Might review again.

    Data is not numeric (quantity) in nature, it is textual (identifiers). Should not be using a number field.

    The data structure is not consistent. InputMask will not easily solve this issue, if at all. https://support.office.com/en-us/art...2-4A47832DE8DA

    Also, Format Fixed and DecimalPlaces 2 will not cause 24001 to display as 240.01. It will show as 24001.00, and again, this does not alter the actual value in field.

    Number or text field, because of inconsistency I expect will need a VBA function to determine placement of periods. What rule(s) determine whether to have 1, 2, 3 digits in the first segment? And a period every 3 digits after?
    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.

  8. #8
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I edited my previous post probably after you read. Might review again.
    You are addressing OP or me?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Meant for OP.
    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.

  10. #10
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    310
    Hi,
    The sequence I am using is part of DCC for books classification (Dewey).
    I will try having a function to put a period (.) after every three digits
    Thanks

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I already have one but if you want to give it a shot as a learning exercise that might be a good idea.

  12. #12
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    310
    I am a beginner in VBA. Can I have the function you have?

  13. #13
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I'll add notes for you then. Will take a few minutes to do that and review.

  14. #14
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Remember, you stated that the table field was of type Long and it was required. If you attempt to use this function in a query calculated field and the field that the function references contains any Null values it will fail as it is written. Your requirement dictates that the output of the function must be a string; e.g. 123456789 becomes 123.456.789 thus cannot be a number. To test function, you can call it like insertdot(12345678)
    To use it in a query, you'd have a calculated field like Dotted: InsertDot([Nums]) where [Nums] is the name of the field that contains your Long values.

    Code:
    Public Function InsertDot(lngIn As Long) As String
    Dim n As Integer, x As Double, y As Integer
    
    x = Len(CStr(lngIn)) / 3 'convert to string to get its length; divide by 3 to count 'sections'
    
    'if x has decimlas, subtracting the integer of x will leave the decimal, thus not be zero
    If x - Int(x) = 0 Then
      y = 1
    Else
    'if there is a decimal portion, round up by adding 1 to the integer value (e.g. 2.6666667 becomes 3)
      x = Int(x) + 1
      y = 1
    End If
    
    For n = 1 To x
    'Mid function begins at y (1 on first pass) and gets 3 characters. We append '.' to it and assign to function's return value
      InsertDot = InsertDot & Mid(lngIn, y, 3) & "."
      y = y + 3 'increment y so as to begin at (e.g. 1+3=4) position in string for next use of Mid function
    Next n
    
    If Right(InsertDot, 1) = "." Then InsertDot = Left(InsertDot, Len(InsertDot) - 1) 'assign all but the ending '.' to the function's return value
    
    Debug.Print InsertDot 'comment out this line when ready to use the function in a query
    
    End Function
    At this point I realize I could shorten the first IF block (which I will probably do in my own version) but I'm in the middle of a posting now, and if it ain't broke....

    EDIT: don't know if you realize that such a function needs to be in a standard module for it to work from a query. Also, you'd need to add a textbox to your form to show the results of the calculated query field. You can keep (or not) the form control that displays the original table field number. If you keep it there, you can also hide it or not. Depends on whether or not you need the original field on the form for other purposes.

  15. #15
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    310
    thank you all for the support.

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

Similar Threads

  1. Input mask
    By Khalil Handal in forum Forms
    Replies: 1
    Last Post: 06-07-2018, 09:31 PM
  2. Input Mask
    By Serge-Nanaimo in forum Access
    Replies: 10
    Last Post: 02-15-2017, 09:10 PM
  3. Input Mask
    By kdbailey in forum Access
    Replies: 4
    Last Post: 12-19-2014, 08:11 AM
  4. Input Mask
    By qbc in forum Access
    Replies: 2
    Last Post: 01-20-2012, 03:27 PM
  5. Input mask
    By doobybug in forum Access
    Replies: 2
    Last Post: 06-17-2009, 09:40 PM

Tags for this Thread

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