infomamun
06-19-2018, 09:25 PM
I have a ms word form with activeX control (not the form control). Suppose I have two textboxes and two option button as follows:
Name: [textBox1]
Address: [textBox2]
Gender: [opt1] Male [opt2] Female
Now if I want a tab order, I have to add following macro:
PrivateSub textBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,ByVal Shift AsInteger)
If KeyCode =9Then
textBox2.Activate
EndIf
EndSub
PrivateSub textBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,ByVal Shift AsInteger)
If KeyCode =9Then
opt1.Activate
EndIf
EndSub
PrivateSub opt1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,ByVal Shift AsInteger)
If KeyCode =9Then
opt2.Activate
EndIf
EndSub
Now in my real form there are 20 text boxes and 12 option buttons, so it is quite boring to write down keydown event for each form field. How can I write a macro so that it will first get the name of current form field on keydown (and validating it as tab keydown) and then go to next form field. For the sake of tab order, I will then rename all form field chronologically such as field1, field2, field3......... etc, so that with an increment the code can move the tab to next form field.
Any help will be appreciated.
As I need urgent help, I have posted this in stackoverflow forum also. Who will answer acceptable help, will get credit. Link is:
https://stackoverflow.com/questions/50939997/how-to-set-tab-order-by-a-macro-in-ms-word
Name: [textBox1]
Address: [textBox2]
Gender: [opt1] Male [opt2] Female
Now if I want a tab order, I have to add following macro:
PrivateSub textBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,ByVal Shift AsInteger)
If KeyCode =9Then
textBox2.Activate
EndIf
EndSub
PrivateSub textBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,ByVal Shift AsInteger)
If KeyCode =9Then
opt1.Activate
EndIf
EndSub
PrivateSub opt1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,ByVal Shift AsInteger)
If KeyCode =9Then
opt2.Activate
EndIf
EndSub
Now in my real form there are 20 text boxes and 12 option buttons, so it is quite boring to write down keydown event for each form field. How can I write a macro so that it will first get the name of current form field on keydown (and validating it as tab keydown) and then go to next form field. For the sake of tab order, I will then rename all form field chronologically such as field1, field2, field3......... etc, so that with an increment the code can move the tab to next form field.
Any help will be appreciated.
As I need urgent help, I have posted this in stackoverflow forum also. Who will answer acceptable help, will get credit. Link is:
https://stackoverflow.com/questions/50939997/how-to-set-tab-order-by-a-macro-in-ms-word