A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Trick behaviour when entering field



 
 
Thread Tools Display Modes
  #1  
Old January 14th, 2008, 09:45 PM posted to microsoft.public.access.forms
tkosel
external usenet poster
 
Posts: 80
Default 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  
Old January 14th, 2008, 09:57 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default 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  
Old January 14th, 2008, 10:03 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default 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  
Old January 14th, 2008, 11:01 PM posted to microsoft.public.access.forms
Mark A. Sam[_3_]
external usenet poster
 
Posts: 468
Default 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  
Old January 14th, 2008, 11:15 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default 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  
Old January 15th, 2008, 11:34 AM posted to microsoft.public.access.forms
Mark A. Sam[_3_]
external usenet poster
 
Posts: 468
Default 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  
Old January 15th, 2008, 06:48 PM posted to microsoft.public.access.forms
tkosel
external usenet poster
 
Posts: 80
Default 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  
Old January 15th, 2008, 07:23 PM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:12 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.