Consulting

Results 1 to 5 of 5

Thread: How to set tab order by a macro in ms word

  1. #1

    How to set tab order by a macro in ms word

    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/...cro-in-ms-word


    Last edited by infomamun; 06-19-2018 at 09:28 PM. Reason: formatting

  2. #2
    As you appear to be at the stage of creating the form, do yourself a favour and save a lot of grief later by using content controls for the from fields in this document.
    You might even find http://www.gmayor.com/insert_content_control_addin.htm useful.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    There is a Donate button in your screen shot of "content controls" UI. Is it a part of the add-in and can't be omitted?

  4. #4
    All the add-ins on my web site are donationware. If you find it useful, send a donation. The format is what you see is what you get.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    GM -- thought I'd take a look at the CC addin


    Norton AV didn't like the EXE in the ZIP file

    Thought I'd check before I overruled the AV to make sure that there's no issues

    I just thought that it's a little unusual to have a EXE with a DOCM file

    Capture.JPG
    Capture2.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •