If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Inputting numbers
I want to ensure data entry people can only type in whole numbers into a
numeric field (Number of children). I have set the field to Byte, but data entry still allows someone to type 1.5, and the number is then rounded. How can I supply an error message or validation rule to not allow decimals to be entered? |
#2
|
|||
|
|||
You can add some code to the KeyPress event of the text box so it destroys
any keystroke that is not a digit. 1. Open your form in design view. 2. Right-click the text box, and choose Properties. 3. Set the On KeyPress property to: [Event Procedure] 4. Click the Build button (...) beside this. Access opens the code window. 5. Between the "Private Sub..." and "End Sub" lines, enter: Call DigitOnly(KeyAscii) 6. In a standard module (Modules tab of Database window), paste the function below: Sub DigitOnly(KeyAscii As Integer) If KeyAscii 48 Or KeyAscii 57 Then If KeyAscii vbKeyBack Then KeyAscii = 0 End If End If End Sub Note: the function also prevents the user from typing a minus sign. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "J LaCross" J wrote in message ... I want to ensure data entry people can only type in whole numbers into a numeric field (Number of children). I have set the field to Byte, but data entry still allows someone to type 1.5, and the number is then rounded. How can I supply an error message or validation rule to not allow decimals to be entered? |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I identify different numbers to a table of numbers | Erich Niemand | Worksheet Functions | 1 | September 9th, 2004 04:25 AM |
Help Needed for Groups Please | Paul Black | General Discussion | 15 | June 21st, 2004 02:54 AM |
TOC using paragraph numbers instead of Page numbers | cmac | Page Layout | 8 | May 16th, 2004 01:32 PM |
Alphanumeric sort with mixed numbers | David Kingsworthy | Worksheet Functions | 1 | September 26th, 2003 05:51 PM |