Results 1 to 7 of 7
  1. #1
    rthakral is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    35

    How to type in number value on screen field w/o having to place cursor at beginning??

    Hi all,

    I'm having trouble with a field on my DB. I have a field named zip code. It has a limit of 5 characters that are only number values, I'm not having any trouble with entering information at all, it's easiest when I just tab into the cell from the previous one. However, the part I am having trouble with is when I click within the field and the cursor, let's say, is at the second character line, and I enter the zipcode 15222, it'll only enter 1522 since my cursor is at the second line.



    How can I fix this so that wherever my cursor is, within the box it'll type the full 5 digit zip code? My boss is insistent on making sure that even if he clicks towards the right of the box, it should type the full number in no questions asked.

    Please advise!!! Any help would be greatly appreciated. Thanks

    Best,
    RT

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Post # 2 has some example code in this thread here
    https://www.accessforums.net/forms/p...eld-38402.html

  3. #3
    rthakral is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    35
    Sorry, I don't know a lick of coding but thank you! I was hoping there would be some kind of an answer within the property fields? Anyone know anything about how to do this?

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Using Linq's code...

    Try this in the control's Got Focus event and tab into the field. I am guessing you have a mask for the field/control, so I would like to test the behavior. Try it with a value and without a value in the field.

    You can create a Got Focus event by highlighting the control and going to the Properties window. Click the Event tab. Click the Elipses(...) next to the Got Focus field. Click Code builder. Your VBA IDE will open. Paste the code below within the Event Handler you just created.

    Code:
      If IsNull(Me.zip_code.Value) Then
       Me.Mzip_code.SelStart = 0
      End If
      
      If Not IsNull(Me.Mzip_codeValue) Then
        If Len(Me.zip_code.Value) < 20 Then
          Me.zip_code.SelStart = 1
        Else
          Me.zip_code.SelStart = 0
       End If
      End If

  5. #5
    rthakral is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2013
    Posts
    35
    I have no problem with it when I tab into the field, that's the way I'm already doing it. But my boss wants to be able to *click* anywhere in the field and have it type properly no matter what!

    I will try this and let you know, give me a few mins.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Okay, You will want the code in the Click event also. It is a good idea to have it in both. So go ahead and add it to the click event too.

  7. #7
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    And... to be specific... the way to enter that code is -
    1) Open the form in design view.
    2) Right-click the textbox control and select "properties" to open the properties pane.
    3) Click on the Events tab in the properties pane.
    4) Click in the box next to the appropriate event (On Got Focus)
    5) Click the button with three dots. (...)
    6) Select Code Builder
    7) Place ItsMe's code between the line that says
    Code:
    Private Sub zip_code_GotFocus()
    and the line that says:
    Code:
    End Sub
    The above instructions (and ItsMe's code) assume that zip_code is the name of the text box.

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

Similar Threads

  1. Replies: 9
    Last Post: 08-20-2013, 09:59 AM
  2. #Type! Error for Number Field in Form
    By CementCarver in forum Forms
    Replies: 4
    Last Post: 06-06-2013, 04:45 PM
  3. Table Number format and decimal place problem
    By DjMorgan in forum Access
    Replies: 3
    Last Post: 04-29-2013, 01:52 AM
  4. Replies: 5
    Last Post: 10-17-2011, 02:53 PM
  5. Replies: 21
    Last Post: 02-14-2011, 02:51 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