Try this:
Private Sub TextBox_Change() Static X As Integer If X = 1 Then NextText.SetFocus X = 0 Else X = X + 1 End If End Sub
Using Static to dim X causes it to remember the value from one call to the next.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Code for # of Keystrokes to Trigger Cursor Move (W
(Edited by SherryThing on 28-Aug-03 22:30. Can’t use a userform for this.)
Does anyone know of any code that would cause the cursor to move to the next formfield after a certain number of keystrokes. What I need is for the cursor to move to the next formfield after any, say, two keystrokes are entered into the current formfield – so the User doesn’t have to hit the Tab key to get to the next formfield. This is a protected form in Word. I need code to do this in the actual Word form document – not in a Userform.
THANKS.
Hi Kevin and Loren Ann,
Thanks for these suggestions. However, I realize now that we need to use the formfields within the actual form document. A userform won’t work with the form we’re working with. So I’m looking for an on-entry macro I suppose, that will cause the cursor to move forward to the next formfield after x number of keystrokes. I don’t know if this is at all possible though…
Sherry
Oh, this is bad. There is an application event in Word known as WindowSelectionChange. It monitors many different types of “moves,” but it does not trigger for continuous typing. So even with all the rigamarole of testing it, it won’t help. This might not be something that Word’s standard Form controls can do.
For future reference, here was the test environment:
Word document with two text fields, the first one limited to 3 characters.
In the document,
Option Explicit Public WithEvents wdApp As Word.Application Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection) ' Write selection "end" position, field name, field "results" to Immediate window Debug.Print Sel.End, Sel.Bookmarks(1).Name, _ ActiveDocument.FormFields(Sel.Bookmarks(1).Name).Result End Sub
Option Explicit Dim wdEvts As New clsWordAppEvents Sub RegisterAppEvtHandler() Set wdEvts.wdApp = Word.Application End Sub
Resized the windows so I could watch the Immediate window as I typed in the document (protected for forms), ran the RegisterAppEvtHandler sub and then tested.
Oh, this is bad. There is an application event in Word known as WindowSelectionChange. It monitors many different types of “moves,” but it does not trigger for continuous typing. So even with all the rigamarole of testing it, it won’t help. This might not be something that Word’s standard Form controls can do.
For future reference, here was the test environment:
Word document with two text fields, the first one limited to 3 characters.
In the document,
Option Explicit Public WithEvents wdApp As Word.Application Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection) ' Write selection "end" position, field name, field "results" to Immediate window Debug.Print Sel.End, Sel.Bookmarks(1).Name, _ ActiveDocument.FormFields(Sel.Bookmarks(1).Name).Result End Sub
Option Explicit Dim wdEvts As New clsWordAppEvents Sub RegisterAppEvtHandler() Set wdEvts.wdApp = Word.Application End Sub
Resized the windows so I could watch the Immediate window as I typed in the document (protected for forms), ran the RegisterAppEvtHandler sub and then tested.
Hi Kevin and Loren Ann,
Thanks for these suggestions. However, I realize now that we need to use the formfields within the actual form document. A userform won’t work with the form we’re working with. So I’m looking for an on-entry macro I suppose, that will cause the cursor to move forward to the next formfield after x number of keystrokes. I don’t know if this is at all possible though…
Sherry
(Edited by SherryThing on 28-Aug-03 22:30. Can’t use a userform for this.)
Does anyone know of any code that would cause the cursor to move to the next formfield after a certain number of keystrokes. What I need is for the cursor to move to the next formfield after any, say, two keystrokes are entered into the current formfield – so the User doesn’t have to hit the Tab key to get to the next formfield. This is a protected form in Word. I need code to do this in the actual Word form document – not in a Userform.
THANKS.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications