If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Trick behaviour when entering field
I have a form for which I want all fields except one to have the text in
entire field selected when that field get the focus. I know that I can effect the behaviour entering field using a Database wide setting under tools, options, keyboard, behaviour entering field. Is there a way to to this for just one field on a form? |
#2
|
|||
|
|||
Trick behaviour when entering field
In either case, use the GotFocus event of the control:
Select it all: Me.MyTextBox.SelLength = Len(Me.MyTextBox) Start at the beginning with nothing selected: Me.MyTextBox.SelStart = 0 -- Dave Hargis, Microsoft Access MVP "tkosel" wrote: I have a form for which I want all fields except one to have the text in entire field selected when that field get the focus. I know that I can effect the behaviour entering field using a Database wide setting under tools, options, keyboard, behaviour entering field. Is there a way to to this for just one field on a form? |
#3
|
|||
|
|||
Trick behaviour when entering field
"tkosel" wrote in message
... I have a form for which I want all fields except one to have the text in entire field selected when that field get the focus. I know that I can effect the behaviour entering field using a Database wide setting under tools, options, keyboard, behaviour entering field. Is there a way to to this for just one field on a form? You can use the control's GotFocus event to set its SelStart or SelLength property -- I don't think it matters which you use. For example: Private Sub ClientName_GotFocus() Me!ClientName.SelStart = 0 End Sub If you want to put the caret at the end of the text instead of the start, you can use this instead: With Me!ClientName .SelStart = Len(.Text) End With -- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup) |
#4
|
|||
|
|||
Trick behaviour when entering field
This will work when tabbing into the textbox, but not is you click on it
with your mouse. For that you can put the code into the KeyUp event. Me.MyTextBox.SelStart = 0 Me.MyTextBox.SelLength = nz(Len(Me.MyTextBox),0) Use the nz(function) to avoid Null errors. Also it has been my experience that the term, Len(Me.MyTextBox) can be problematic, so I also use the number 255 rather than the len() function. Me.MyTextBox.SelLength = 255 God Bless, Mark A. Sam "Klatuu" wrote in message ... In either case, use the GotFocus event of the control: Select it all: Me.MyTextBox.SelLength = Len(Me.MyTextBox) Start at the beginning with nothing selected: Me.MyTextBox.SelStart = 0 -- Dave Hargis, Microsoft Access MVP "tkosel" wrote: I have a form for which I want all fields except one to have the text in entire field selected when that field get the focus. I know that I can effect the behaviour entering field using a Database wide setting under tools, options, keyboard, behaviour entering field. Is there a way to to this for just one field on a form? |
#5
|
|||
|
|||
Trick behaviour when entering field
"Mark A. Sam" wrote in message
... This will work when tabbing into the textbox, but not is you click on it with your mouse. For that you can put the code into the KeyUp event. Me.MyTextBox.SelStart = 0 Me.MyTextBox.SelLength = nz(Len(Me.MyTextBox),0) Use the nz(function) to avoid Null errors. If you refer to the text box's Text property, you don't need the Nz function, because the Text property (as distinct from the Value property) can never be Null. Also it has been my experience that the term, Len(Me.MyTextBox) can be problematic, so I also use the number 255 rather than the len() function. Me.MyTextBox.SelLength = 255 That won't work for a text box that is bound to a memo field, or unbound -- in either of those cases, the text box could be holding more than 255 characters of text. -- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup) |
#6
|
|||
|
|||
Trick behaviour when entering field
That won't work for a text box that is bound to a memo field, or unbound -- in either of those cases, the text box could be holding more than 255 characters of text. I agree. I wasn't thinking of usage with a memo field. My experience is to not select all of a memo field. Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup) |
#7
|
|||
|
|||
Trick behaviour when entering field
To All,
Thanks, many of your suggestions were very usable and I have the issue solved. I appreciate the tips very much. "Dirk Goldgar" wrote: "tkosel" wrote in message ... I have a form for which I want all fields except one to have the text in entire field selected when that field get the focus. I know that I can effect the behaviour entering field using a Database wide setting under tools, options, keyboard, behaviour entering field. Is there a way to to this for just one field on a form? You can use the control's GotFocus event to set its SelStart or SelLength property -- I don't think it matters which you use. For example: Private Sub ClientName_GotFocus() Me!ClientName.SelStart = 0 End Sub If you want to put the caret at the end of the text instead of the start, you can use this instead: With Me!ClientName .SelStart = Len(.Text) End With -- Dirk Goldgar, MS Access MVP www.datagnostics.com (please reply to the newsgroup) |
#8
|
|||
|
|||
Trick behaviour when entering field
SelLength and SelStart both take an Integer as an argument (which is limited
to 32,767) but a Memo field can hold twice that many characters (actually 4 times that, I understand, if the data is entered via code) so you have to be careful using them with these fields! I can't imagine selecting an entire memo field, but if you wanted to, say, place the cursor at the end of the field, you should test it's length and if Len(YourMemoField) 32767 set it to 32767, which would at least get you a whole lot closer to the end of the data. If Len(YourMemoField) 32767 Then YourMemoField.SelStart = 32767 Else YourMemoField.SelStart = Len(YourMemoField) End If -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000/2003 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...forms/200801/1 |
Thread Tools | |
Display Modes | |
|
|