My Assistant
![]() ![]() |
|
|
Feb 27 2012, 08:31 AM
Post
#1
|
|
|
UtterAccess Addict Posts: 262 |
Hello Group,
I have an unbound textbox on a form that updates a subform using a rst... After the user enters a value in the unbound textbox and presses [Enter], I'd like the value in the textbox to remain and for it to become highlighted so that the user can still see it, but can start typing another value (meaning the focus remains on the unbound textbox). I've tried using SelStart and SelLength in the textbox's AfterUpdate event, but it doesn't work. After [Enter] is pressed, the focus goes to the next control. I've also tried setting the focus back to the textbox (which works), but I cannot get the text to highlight (I can only delete it). I think it has something to do with the order of events, but I'm not sure. Any thoughts? alex |
|
|
|
Feb 27 2012, 08:46 AM
Post
#2
|
|
|
UA Editor + Utterly Certified Posts: 22,722 From: Melton Mowbray,Leicestershire (U.K) |
Hi
QUOTE the focus goes to the next control. Have you tried setting the forms event "Cycle" to "Current Record".. (IMG:style_emoticons/default/thumbup.gif) |
|
|
|
Feb 27 2012, 09:46 AM
Post
#3
|
|
|
UtterAccess Addict Posts: 262 |
Thanks Larry for responding.
Nothing changes when I adjust that property...the focus goes to the next control (which in this case is the first control). Here's my code: Private Sub txtBox_AfterUpdate() 'focus goes to next ctl when user presses [Enter] 'setting the focus back to this ctl only sets the cursor at the beginning Me.txtBox.SelStart = 0 Me.txtBox.SelLength = 10 End Sub |
|
|
|
Feb 27 2012, 10:08 AM
Post
#4
|
|
|
UtterAccess VIP Posts: 7,589 From: South coast, England |
Hi Alex
On your form try the following: 1. Create a private variable at the top of the VBA window after the option statements Private BolSel As Boolean 2. In the AFTER UPDATE event of the field you're changing add the line BolSel = -1 3. In the ON ENTER event of the field with the next tab (ie the field the cursor nornally moves to) add the code: CODE If BolSel = -1 Then Me.Field1.SetFocus Me.Field1.SelStart = 0 Me.Field1.SelLength = Len(Me.Field1.Text & "") BolSel = 0 End If Replacing 'Field1' with the name of the text box you are changing. hth |
|
|
|
Feb 27 2012, 10:33 AM
Post
#5
|
|
|
UtterAccess Addict Posts: 262 |
Bernie,
Thanks for the help! I created a 'dummy textbox' and (as you suggested) set the focus back to the applicable textbox in the OnEnter event of the dummy (which I set as the next tab stop) and it seems to be working perfectly... I don't even need SelStart or SelLength...simply setting the focus back to the control highlights the text inside the textbox. Seems like a silly way to accomplish a simple task, but.... Thanks again, alex |
|
|
|
Feb 27 2012, 10:44 AM
Post
#6
|
|
|
UtterAccess VIP Posts: 7,589 From: South coast, England |
(IMG:style_emoticons/default/yw.gif)
Yes it does seem like a silly way but there you go .... An alternative, for the 'OnEnter' Event which means you don't need the private variable is: CODE If Screen.PreviousControl.Name = "Field1" Then Me.Field1.SetFocus Note that the selection for the whole text in the field depends on your default settings, which is why I'd included the selection in my first post. hth |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 22nd May 2013 - 10:09 AM |