none
Use active X control like drop down box in internet explorer... RRS feed

  • Question

  • Hello All,

     

     

    I have a Word Form with several active X controls using this code here

     

     

    Sub Document_Open()
      Dim sel() As String
      Dim wd As Long
      ComboBox1.Clear
      sel = Split("Black,Blue,Brown,", ",")
      For wd = 0 To UBound(sel())
        ComboBox1.AddItem sel(wd)
      Next
      ComboBox1.ListIndex = 0
    End Sub

     

     

     

     

    When tabbing to the first particular activex control, the box properly defaults to "Black".

    However, the only way for me to select "Brown" is to use the backspace key and delete ALL of Black and then, finally, type "B" three times to get to "Brown" (using mMatchEntryFirstLetter 0 in the properties of the combo box).

    I would like to tab to that box and type "B" three times to select "Brown" without having to clear out "Black" first.

    Can this be done?


     

    Thanks Much

    Tuesday, November 30, 2010 6:39 PM

Answers

  • <<Well....it kind of works..the way that it doesn't work is that it allows me to type a single letter into the combo box and then tab away from it. I want it to ONLY allow letters relevant to the contents of the combo box to be typed.>>

    Look at the Properties for the control. You want the "Style" property. Set it to frmStyleDropdownList.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by digdugger Thursday, December 9, 2010 4:28 PM
    • Unmarked as answer by digdugger Thursday, December 9, 2010 4:29 PM
    • Marked as answer by digdugger Thursday, December 9, 2010 4:35 PM
    Thursday, December 9, 2010 10:52 AM
    Moderator

All replies

  • Well, there's an EnterFieldBehavior property that should control whether the combobox automatically selects all, or "remembers" the previous selection. Apparently, that doesn't work when the Userform control is embedded in the document.

    But you can work with the GotFocus event of the control to force the selection:

    Private Sub ComboBox1_GotFocus()
        ComboBox1.SelStart = 0
        ComboBox1.SelLength = Len(ComboBox1.Text)
    End Sub

    Note that the user wouldn't have to press Backspace n times, if you don't want to use the event. Shift+Home would select to the beginning of the control. Pressing Up- + Down-Arrow will scroll through the list (even if it's not dropped down).


    Cindy Meister, VSTO/Word MVP
    Wednesday, December 1, 2010 12:01 PM
    Moderator
  • Cindy,

    Sorry for the delay and thanks much for the response. My goal is to tab to the box and hit "B" 3 times to select "Brown", just like on website using Internet Explorer.

    For example, when filling out a form and I come to the state field, I hit "C" three times and get to Connecticut. I don't have to do any keyboard combinations.

    Is there a way to mimic that behavior in Word?

     

    Thanks Much

    Thursday, December 2, 2010 7:10 PM
  • The suggestion I made, which will let you "start at the beginning" would let the user type Bla, Blu, or Br to get the "match". I think that's as close as you're going to get. The Internet changed how comboboxes work (and personally, I hate it): it matches only the first character. The "old" COM comboboxes match as you type. There's no way to turn the one into the other, I'm afraid...


    Cindy Meister, VSTO/Word MVP
    Thursday, December 2, 2010 7:14 PM
    Moderator
  • Cindy,

    Okay, I got the code to work as I desired...BUT... only for one combo box. I tried to copy and paste the combo box into another table area and it doesn't work on the second one.

    Here's the code I tried..

    Dim sel() As String
     Dim wd As Long
    Sub Document_Open()
     'Dim sel() As String
     'Dim wd As Long
     
     ComboBox1.Clear
     sel = Split("Black,Blue,Brown", ",")
     For wd = 0 To UBound(sel())
      ComboBox1.AddItem sel(wd)
     Next
     
     End Sub
    
     Sub ComboBox11_Change()
     'Dim sel() As String
     'Dim wd As Long
     ComboBox11.Clear
     sel = Split("Banana,Berry", ",")
     For wd = 0 To UBound(sel())
      ComboBox11.AddItem sel(wd)
     Next
    End Sub

     

     

    I also tried this...

     Dim sel() As String
     Dim wd As Long
    
    Sub Document_Open()
     'Dim sel() As String
     'Dim wd As Long
     
     ComboBox1.Clear
     sel = Split("Black,Blue,Brown", ",")
     For wd = 0 To UBound(sel())
      ComboBox1.AddItem sel(wd)
     Next
     
     
     ComboBox11.Clear
     sel = Split("Berry,Banana", ",")
     For wd = 0 To UBound(sel())
      ComboBox11.AddItem sel(wd)
     Next
     
      
    End Sub

    Why can I only get one combo box to work and what do I need to do to make multiple combo boxes work?

    Thanks much for all your help.

    • Edited by digdugger Friday, December 3, 2010 4:25 PM tried to get the code in block format but doesn't seem to work
    Friday, December 3, 2010 4:18 PM
  • <<I tried to copy and paste the combo box into another table area and it doesn't work on the second one.>>

    1. HOW does it not work

    2. If you insert a new combobox, rather than copy/paste (and delete the one you copied), does that behave any differently?

    3. Which version of Word are we dealing with?


    Cindy Meister, VSTO/Word MVP
    Saturday, December 4, 2010 8:00 AM
    Moderator
  • Hi Cindy,

    Okay, (again, sorry for the delay)...

    Well....it kind of works..the way that it doesn't work is that it allows me to type a single letter into the combo box and then tab away from it. I want it to ONLY allow letters relevant to the contents of the combo box to be typed.

    For example...

    The first box has values of Black, Blue or Brown. Currently, I am able to type "A" and then tab away from that box, leaving "A" there. I would like the combo box to show nothing unless the first letter typed is "B" and only "B". If any other letter is typed, it would show nothing (just like Internet drop down boxes).

    Is there code that will only except the first letter if that first letter matches a first letter from a value in the drop down box and otherwise show nothing if no match?

    Also, I was wrong in that both boxes do behave the same (incorrectly so) therefore, my dilemna is getting one box to work properly, once I get the first box to behave properly, the code for the other box should behave indentically.

    I have found another nuance...

    From the values I have in my combo box, is there a way to have it default to the value of my choice AND have that whole word selected?

    Currently, if I have the word/value of my choice selected, it highlights all but the first letter, for example, if I have "Brown" as my default choice "rown" is highlighted, leaving the "B" un-highlighted.

    Why is this important you ask? Well, if I want to then change my value to "Black", I can't hit "B" anymore, because then a value of "BB" shows up. This requires me to backspace out of the whole word and THEN...finally...hit "B" "B" to get to "Black".

    By highlighting the whole word from the getgo, I can then hit "B" and easily change my value from "Brown" to "Black" (because the whole word is highlighted and the value is then written over).

    Thanks much! :)

    • Edited by digdugger Wednesday, December 8, 2010 4:44 PM another nuance
    Wednesday, December 8, 2010 3:33 PM
  • <<Well....it kind of works..the way that it doesn't work is that it allows me to type a single letter into the combo box and then tab away from it. I want it to ONLY allow letters relevant to the contents of the combo box to be typed.>>

    Look at the Properties for the control. You want the "Style" property. Set it to frmStyleDropdownList.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by digdugger Thursday, December 9, 2010 4:28 PM
    • Unmarked as answer by digdugger Thursday, December 9, 2010 4:29 PM
    • Marked as answer by digdugger Thursday, December 9, 2010 4:35 PM
    Thursday, December 9, 2010 10:52 AM
    Moderator
  • Purrffecttion!

     

    Thanks so much for sticking with me on this Cindy!

    Thursday, December 9, 2010 4:30 PM