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?
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?
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!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)>will try this out
I get an invalid use of null error 94.... use nz()?
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
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.
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?![]()
I went withSorry, 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 Subhowever 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....?Code:If Nz(Me.PaymentReceived1st, "") <> "" Then Me.PaymentReceived1st.SelStart = 0 Me.PaymentReceived1st.SelLength = Len(Me.PaymentReceived1st) End If
maybe use something else?
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??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)>
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..
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.
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! IWorks 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)>will see if I can manage to get the same outcome and post back asap