Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / November 2007

Tip: Looking for answers? Try searching our database.

Restrict Text Box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Abdul Shakeel - 12 Nov 2007 12:46 GMT
Hi All,

I want that in My Access Form in one of my Text box only Numeric values
should enter when user try to enter text in it,......nothing should happen
Allen Browne - 12 Nov 2007 12:57 GMT
In table design, if you set the Data Type of the field to Number, Access
will reject any entry that is not a valid number.

If you want to block any characters that are not digits (including the
decimal point, negative sign, etc.) you could paste the function below into
a general module, and then set your text box's On KeyPress property to:
   [Event Procedure]
and add the code:
   Call DigitOnly(KeyAscii)

Sub DigitOnly(KeyAscii As Integer)
On Error GoTo Err_DigitOnly
   'Purpose:   Disallow any keystroke except 0 ~ 9, and backspace.
   'Usage:     In a text box's KeyPress event procedure:
   '               Call DigitOnly(KeyAscii)

   If KeyAscii < 48 Or KeyAscii > 57 Then
       If KeyAscii <> vbKeyBack Then
           KeyAscii = 0
       End If
   End If

Exit_DigitOnly:
   Exit Sub

Err_DigitOnly:
   MsgBox "Error " & Err.Number & ": " & Err.Description
   Resume Exit_DigitOnly
End Sub

Note that this code will have the side effect of disabling any non-digit
hotkeys while this text box has focus.

Signature

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.

> Hi All,
>
> I want that in My Access Form in one of my Text box only Numeric values
> should enter when user try to enter text in it,......nothing should happen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.