Results 1 to 9 of 9
  1. #1
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239

    Field default value + limit entry to numbers only

    Hi,

    I need to input in Textbox default value "1234-", and after that only allow to input numbers.

    If I format field to number, "-" is recognized as invalid character, but If I format Textbox to text, user can enter letters too.



    Is there any way to achieve this ?

  2. #2
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Maybe input mask? like:
    "1234-"0000
    And field format must be text for that.

  3. #3
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    Maybe input mask? like:
    "1234-"0000
    And field format must be text for that.
    No, this is not working, unfortunally. Whether text or number field format, It returns "1234-1234".

  4. #4
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    What is not working? It works for me, just tested.
    Click image for larger version. 

Name:	mask1.png 
Views:	13 
Size:	105.6 KB 
ID:	23678
    Click image for larger version. 

Name:	mask2.jpg 
Views:	13 
Size:	55.4 KB 
ID:	23679

  5. #5
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    I'm sorry, I wasn't clear enough. Not table field, display of textbox in form. It displays me as I mentioned.

    I tried this too: "1234-"999999999, and It works, but...Is there any way to get rid of underline (underscore) character ? I would rather use msgbox that would alert user for wrong input ?

  6. #6
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Same input mask applied to textbox on form works as well for me...
    And if you want to get rid of underscore, set input mask to:
    "1234-"000000000;;" "
    Last part after ";" describes placeholder character.
    Click image for larger version. 

Name:	mask4.jpg 
Views:	12 
Size:	51.3 KB 
ID:	23681

    Click image for larger version. 

Name:	mask3.jpg 
Views:	12 
Size:	21.8 KB 
ID:	23682

    If you don't know how many digits will need to be inputted then of course "1234-"999999999;;" ", as you mentioned.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Not really sure about the exact Input Mask you need, since it depends on whether or not the number of digits to be entered is fixed or variable, but after you get that straight, this code will only allow the physical entry (by keyboard) of digits, and pops up a MessageBox if the user attempts to enter alpha characters. The code also allows for entry from the KeyPad and allows the use of navigation keys.

    Code:
     Private Sub YourTextBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
    
      Select Case KeyCode
    
       Case 48 To 57
    
       'Do nothing: Numerical characters (digits) are allowed
    
       Case vbKeyDelete, vbKeyBack, vbKeyReturn, vbKeyRight, vbKeyLeft, vbKeyTab
    
       'Do nothing: Allow Delete and Navigation keys to be used
    
       Case vbKeyNumpad0, vbKeyNumpad1, vbKeyNumpad2, vbKeyNumpad3, vbKeyNumpad4, vbKeyNumpad5, vbKeyNumpad6, vbKeyNumpad7, vbKeyNumpad8, vbKeyNumpad9
    
       'Do nothing: Allow input from Numbers Keypad
    
       Case Else
    
       'Don't allow any other keys to be used
    
      MsgBox "Please Enter Digits Only!"
    
      KeyCode = 0
    
      End Select
    
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    Great,

    exactly what I need, combination of both does the trick !

    First, input mask as I want, and then a custom Msgbox if user types anything that is not allowed in field

    Thanks to both of you !!!

    EDIT:

    I also added code for custom Msgbox on input mask violation :

    Code:
     Private Sub Form_Error (DataErr As Integer, Response As Integer)
          Const INPUTMASK_VIOLATION = 2279
          If DataErr = INPUTMASK_VIOLATION Then
             MsgBox "There was an input mask violation!"
             Response = acDataErrContinue
          End If
       End Sub
    Maybe somebody will find It useful.

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The Error Messages the Access Gnomes produce are often confusing and seldom helpful, to the average end-user, and 're-writing' them, using the Form_Error event, is something I've frequently done!

    Glad we could help!

    Good luck with your project!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 14
    Last Post: 06-18-2015, 04:09 PM
  2. Replies: 7
    Last Post: 03-05-2015, 07:34 AM
  3. Limit data entry based on another field
    By chemengr in forum Forms
    Replies: 5
    Last Post: 01-02-2014, 01:21 PM
  4. Default Value - Last Entry
    By jnb22019 in forum Programming
    Replies: 3
    Last Post: 04-20-2012, 08:14 AM
  5. Generating Part Numbers From Field Entry
    By JMac in forum Database Design
    Replies: 10
    Last Post: 02-20-2012, 07:12 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