A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Inputting numbers



 
 
Thread Tools Display Modes
  #1  
Old October 14th, 2004, 06:39 PM
J LaCross
external usenet poster
 
Posts: n/a
Default 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  
Old October 15th, 2004, 03:55 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 01:49 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.