Results 1 to 9 of 9
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    How to stop entry of decimal in table Datasheet view

    I've hunted around here and in Google, and don't see how to inhibit a decimal entry for a currency field.
    Suppose I'm in Mexico, where they don't have fractions of a peso.
    I don't want someone entering 56.7 pesos into a table or query or form.
    As best as I can test, setting the Decimal property to "0" only controls how many decimals to display.
    Which property is best to do this with? (validation I suppose, but how?)

  2. #2
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    If possible, change the field type to Long Integer. This field type doesn't accept decimals. You can add the currency format to the forms and reports where you show the data.
    If you can't change the field type and the field should accept decimals in certain cases you can add conditional validation in your forms with VBA.

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    I´m trying to do it for the currency type, and everywhere based on the table, not just in forms

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Either use validation or you can use the clng or round functions (with 0 do) in the control beforeupdate event

    Or use the key press event to check the character typed and ignore it
    Or use the change event if user can copy paste

  5. #5
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    or use an input mask

  6. #6
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    I don't know if validation is true/false, but if it is then a test to see if the Int(entered value) <> entered value then validation fails. Show the error message.But I'm also going to have a validation for range of data entered, so it may be that I can't have two validations?

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    No reason you can’t combine the two if you use vba. The validation rule property can have multiple validations but will only come back with a single standard message quoting the entire rule if validation is not met

  8. #8
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Can't you put a trigger/data macro on the table to do the job?

  9. #9
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    In the validation for the field I put this, and it worked:
    >-999 And <9999 And Int([MyCustom])=[MyCustom]
    I had no luck using Between, it doesn't seem to like an "and" in the expression, as best as I can tell
    But I want to change MyCustom to something like "Me" so that it will pull the current entry. In other words, when I automate the placement of this validation, I don't want to have to put in every field name, just a self-reference.
    What can I use for Me here?

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

Similar Threads

  1. Stop auto increment of decimal value to 1
    By SierraJuliet in forum Forms
    Replies: 3
    Last Post: 01-24-2019, 01:10 AM
  2. Replies: 5
    Last Post: 08-30-2017, 09:24 PM
  3. Replies: 2
    Last Post: 01-28-2014, 10:13 PM
  4. Replies: 3
    Last Post: 08-18-2013, 09:14 PM
  5. Replies: 6
    Last Post: 11-21-2012, 05:10 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