Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Tab to field, field contents selected - how?

    I have one particular form where the user wants to tab to one particular field and have it selected/highlighted so that when they type it types over without them having to select the text.



    How would one do this? Any suggestions?

  2. #2
    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
    You have to code it in two events, if you want it to work if they Click into the field as well as when they Tab into it. Common sense would dictate that either the GotFocus or the OnEnter events would work for this, in either case, but common sense doesn't always rule in Access!

    Code:
    Private Sub TargetControl_Click()
      Me.TargetControl.SelStart = 0
      Me.TargetControl.SelLength = Len(Me.TargetControl)
    End Sub
    
    Private Sub TargetControl_Enter()
      Me.TargetControl.SelStart = 0
      Me.TargetControl.SelLength = Len(Me.TargetControl)
    End Sub


    Linq ;0)>

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    You have to code it in two events, if you want it to work if they Click into the field as well as when they Tab into it. Common sense would dictate that either the GotFocus or the OnEnter events would work for this, in either case, but common sense doesn't always rule in Access!

    Code:
    Private Sub TargetControl_Click()
      Me.TargetControl.SelStart = 0
      Me.TargetControl.SelLength = Len(Me.TargetControl)
    End Sub
    
    Private Sub TargetControl_Enter()
      Me.TargetControl.SelStart = 0
      Me.TargetControl.SelLength = Len(Me.TargetControl)
    End Sub


    Linq ;0)>
    Thanks! will try this out

  4. #4
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I get an invalid use of null error 94.... use nz()?

  5. #5
    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
    Sorry, knew I had to cover that, but got distracted by my Bully Bitch telling me she needed to go outside to raise the water table! You simply don't run the code if the field is Null.

    Code:
    Private Sub TargetControl_Click()
      If Nz(Me.TargetControl,"") <> "" Then
        Me.TargetControl.SelStart = 0
        Me.TargetControl.SelLength = Len(Me.TargetControl)
      End If
    End Sub
    
    Private Sub TargetControl_Enter()
      If Nz(Me.TargetControl,"") <> "" Then
        Me.TargetControl.SelStart = 0
        Me.TargetControl.SelLength = Len(Me.TargetControl)
      End If
    End Sub

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Here's how I handle it:

    Private Sub cbxStrengthUnits_Enter()
    Me.cbxStrengthUnits.SelLength = Len(Nz(Me.cbxStrengthUnits, ""))
    Me.cbxStrengthUnits.Dropdown
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    Sorry, knew I had to cover that, but got distracted by my Bully Bitch telling me she needed to go outside to raise the water table! You simply don't run the code if the field is Null.

    Code:
    Private Sub TargetControl_Click()
      If Nz(Me.TargetControl,"") <> "" Then
        Me.TargetControl.SelStart = 0
        Me.TargetControl.SelLength = Len(Me.TargetControl)
      End If
    End Sub
    
    Private Sub TargetControl_Enter()
      If Nz(Me.TargetControl,"") <> "" Then
        Me.TargetControl.SelStart = 0
        Me.TargetControl.SelLength = Len(Me.TargetControl)
      End If
    End Sub

    raise the what table?

  8. #8
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Here's how I handle it:

    Private Sub cbxStrengthUnits_Enter()
    Me.cbxStrengthUnits.SelLength = Len(Nz(Me.cbxStrengthUnits, ""))
    Me.cbxStrengthUnits.Dropdown
    End Sub

    Me.cbxStrengthUnits.Dropdown ?

    It is a currency text field if that doesn't confuse the situation...

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    Sorry, knew I had to cover that, but got distracted by my Bully Bitch telling me she needed to go outside to raise the water table! You simply don't run the code if the field is Null.

    Code:
    Private Sub TargetControl_Click()
      If Nz(Me.TargetControl,"") <> "" Then
        Me.TargetControl.SelStart = 0
        Me.TargetControl.SelLength = Len(Me.TargetControl)
      End If
    End Sub
    
    Private Sub TargetControl_Enter()
      If Nz(Me.TargetControl,"") <> "" Then
        Me.TargetControl.SelStart = 0
        Me.TargetControl.SelLength = Len(Me.TargetControl)
      End If
    End Sub
    I went with
    Code:
     If Nz(Me.PaymentReceived1st, "") <> "" Then    
    Me.PaymentReceived1st.SelStart = 0
        Me.PaymentReceived1st.SelLength = Len(Me.PaymentReceived1st)
      End If
    however it only selects either the first character or first 3 (I have some values in the thousands of dollars). Why I can't figure out....?

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    maybe use something else?

  11. #11
    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
    Don't know what to tell you! This is old tried and true code.

    Len(Me.PaymentReceived1st)

    gives you the number of characters in the Control, so the line


    Me.PaymentReceived1st.SelLength = Len(Me.PaymentReceived1st)

    tells Access to select the number of characters that are in the Control, i.e.

    Len(Me.PaymentReceived1st).

    Controls can and do become corrupt, during development, and that the first thing I think of when something simple, like this, doesn't work. The test and the fix are one and them same; delete the original Control and re-create it.

    I know of no other way, using code, to accomplish this task. You can set it, using Options, so that the entire field is selected, on entering it, but that is Access-wide, meaning it applies to all Controls on all Access dbs run on that machine, which, as a rule, is very dangerous!

    Linq ;0)>

  12. #12
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    Don't know what to tell you! This is old tried and true code.

    Len(Me.PaymentReceived1st)

    gives you the number of characters in the Control, so the line


    Me.PaymentReceived1st.SelLength = Len(Me.PaymentReceived1st)

    tells Access to select the number of characters that are in the Control, i.e.

    Len(Me.PaymentReceived1st).

    Controls can and do become corrupt, during development, and that the first thing I think of when something simple, like this, doesn't work. The test and the fix are one and them same; delete the original Control and re-create it.

    I know of no other way, using code, to accomplish this task. You can set it, using Options, so that the entire field is selected, on entering it, but that is Access-wide, meaning it applies to all Controls on all Access dbs run on that machine, which, as a rule, is very dangerous!

    Linq ;0)>
    can a control really be corrupted??

    It's fairly new the database...

    I see the logic I just can't get it to select all the text and I was thinking that may be due to the fact that it is a currency/number field or something..

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Guess I've never tried this with a number field. Just tested Len() function (in the immediate window) on number value and it errors. Although it does work with a date. However, if it works on the content of a control for Linq, it should for you. Try recreating the control.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    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
    Works for Numbers, for me, but I just checked it against a Currency Field and there is, indeed, a problem! For a value of

    • $0.00 Len yields 1
    • $123.00 Len yields 3
    • $123.10 Len yields 5
    • $123.01 Len yields 6

    So,
    • It never counts the currency sign (dollar, in my case).
    • Only counts the Decimal Point if there are cents involved
    • Only counts the first decimal place if it is non-Zero or if the second decimal place is non-Zero
    • Does count dollars, even if it is Zero dollars

    Even wrapping the Currency Value in CStr() to convert it to a string before running Len doesn't help! But what does work, which surprised me, is that you can assign an arbitrary number that is long enough to cover all eventualities, and it will work!

    Change

    Me.PaymentReceived1st.SelLength = Len(Me.PaymentReceived1st)

    to

    Me.PaymentReceived1st.SelLength = 20

    will hilite everything up to twenty characters! You can increase that if you need to!

    Linq ;0)>

  15. #15
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by Missinglinq View Post
    Works for Numbers, for me, but I just checked it against a Currency Field and there is, indeed, a problem! For a value of

    • $0.00 Len yields 1
    • $123.00 Len yields 3
    • $123.10 Len yields 5
    • $123.01 Len yields 6

    So,
    • It never counts the currency sign (dollar, in my case).
    • Only counts the Decimal Point if there are cents involved
    • Only counts the first decimal place if it is non-Zero or if the second decimal place is non-Zero
    • Does count dollars, even if it is Zero dollars

    Even wrapping the Currency Value in CStr() to convert it to a string before running Len doesn't help! But what does work, which surprised me, is that you can assign an arbitrary number that is long enough to cover all eventualities, and it will work!

    Change

    Me.PaymentReceived1st.SelLength = Len(Me.PaymentReceived1st)

    to

    Me.PaymentReceived1st.SelLength = 20

    will hilite everything up to twenty characters! You can increase that if you need to!

    Linq ;0)>
    20 numbers is more than enough! I will see if I can manage to get the same outcome and post back asap

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 07-28-2013, 04:52 PM
  2. Replies: 11
    Last Post: 07-05-2013, 08:00 AM
  3. Replies: 3
    Last Post: 05-23-2011, 07:29 AM
  4. Replies: 0
    Last Post: 03-29-2011, 04:11 PM
  5. Copy contents of one field to another
    By 10 Gauge in forum Forms
    Replies: 4
    Last Post: 02-11-2011, 09:51 AM

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