Adding to a combo box or text box through the keyboard 
Author Message
 Adding to a combo box or text box through the keyboard

There are two problems I am encountering using a toolbar. First, when I
enter a word in the combobox, through the keyboard and press the "Add"
button the word is not entered into the combobox list. Last, when I enter a
word into the text box and press the "Add" button the msgbox does not show
the word.

See the code below.

Public OutlineBar As CommandBar
Public Outline_combobox As CommandBarComboBox
Public Outline_TextBox As CommandBarControl

Private Sub MakeToolbar()
    Dim AddButton As CommandBarButton
    On Error Resume Next
    OutlineBar.Delete
    Set OutlineBar = CommandBars.Add(Name:="OutlineBar",
Position:=msoBarFloating)
    Set Outline_combobox = OutlineBar.Controls.Add(Type:=msoControlComboBox,
temporary:=True)
    Set Outline_TextBox = OutlineBar.Controls.Add(Type:=msoControlEdit,
temporary:=True)
    Set AddButton = OutlineBar.Controls.Add(Type:=msoControlButton,
temporary:=True)
    With Outline_combobox
        .DropDownLines = 5
        .DropDownWidth = 75
        .ListIndex = 0
    End With
    With AddButton
        .Caption = "Add"
        .Style = msoButtonCaption
        .OnAction = "AddVar"
    End With
OutlineBar.Visible = True
End Sub

Private Sub AddVar()
    Outline_combobox.AddItem Outline_combobox.Text
    MsgBox Outline_TextBox.Text
End Sub



Tue, 06 Apr 2004 21:06:55 GMT  
 Adding to a combo box or text box through the keyboard
Hi Steve,

The problem here is that when you click the "Add" button, the focus shifts
from the combobox/textbox to the "Add" button and the text you entered in
these buttons is deleted. To trigger an action in the combobox/textbox, you
enter the text and press the Enter button (on the keyboard). Try the
following code to create the toolbar & controls. When you enter text in the
controls, press the Enter button. BTW, the Temporary parameter for
commandbars / commandbarcontrols does not work.

'-------------------------------------------------------------

Private Sub MakeToolbar()

Dim OutlineBar As CommandBar
Dim Outline_Combobox As CommandBarComboBox
Dim Outline_TextBox As CommandBarControl

Set OutlineBar = CommandBars.Add _
    (Name:="OutlineBar", Position:=msoBarFloating)
Set Outline_Combobox = OutlineBar.Controls.Add _
    (Type:=msoControlComboBox)
Set Outline_TextBox = OutlineBar.Controls.Add _
    (Type:=msoControlEdit)

With Outline_Combobox
    .DropDownLines = 5
    .DropDownWidth = 75
    .ListIndex = 0
    .OnAction = "AddVarCombo"
End With

With Outline_TextBox
    .OnAction = "AddVarText"
End With

OutlineBar.Visible = True

End Sub
'-------------------------------------------------------------

Private Sub AddVarCombo()

    With CommandBars("OutlineBar").Controls(1)
        .AddItem .Text
    End With

End Sub

Private Sub AddVarText()

    MsgBox CommandBars("OutlineBar").Controls(2).Text

End Sub

'-------------------------------------------------------------

Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.



Wed, 07 Apr 2004 11:56:36 GMT  
 Adding to a combo box or text box through the keyboard
Thanks "Ibby",

I now added code (if .listbox = 0 then, .additem .Text, end if) to the
AddVarCombo sub to prevent adding to the combobox when an item is chosen.

I didn't understand the comment about the temporary parameter for
commandbars being ineffective. With the temporary parameter being used
should'nt the command bar dissapear the next time word is open?


Quote:
> Hi Steve,

> The problem here is that when you click the "Add" button, the focus shifts
> from the combobox/textbox to the "Add" button and the text you entered in
> these buttons is deleted. To trigger an action in the combobox/textbox,
you
> enter the text and press the Enter button (on the keyboard). Try the
> following code to create the toolbar & controls. When you enter text in
the
> controls, press the Enter button. BTW, the Temporary parameter for
> commandbars / commandbarcontrols does not work.

> '-------------------------------------------------------------

> Private Sub MakeToolbar()

> Dim OutlineBar As CommandBar
> Dim Outline_Combobox As CommandBarComboBox
> Dim Outline_TextBox As CommandBarControl

> Set OutlineBar = CommandBars.Add _
>     (Name:="OutlineBar", Position:=msoBarFloating)
> Set Outline_Combobox = OutlineBar.Controls.Add _
>     (Type:=msoControlComboBox)
> Set Outline_TextBox = OutlineBar.Controls.Add _
>     (Type:=msoControlEdit)

> With Outline_Combobox
>     .DropDownLines = 5
>     .DropDownWidth = 75
>     .ListIndex = 0
>     .OnAction = "AddVarCombo"
> End With

> With Outline_TextBox
>     .OnAction = "AddVarText"
> End With

> OutlineBar.Visible = True

> End Sub
> '-------------------------------------------------------------

> Private Sub AddVarCombo()

>     With CommandBars("OutlineBar").Controls(1)
>         .AddItem .Text
>     End With

> End Sub

> Private Sub AddVarText()

>     MsgBox CommandBars("OutlineBar").Controls(2).Text

> End Sub

> '-------------------------------------------------------------

> Hope this helps.
> ibby

> Please post replies or follow-ups to the **newsgroup** so that
participants
> may benefit or contribute.



Fri, 09 Apr 2004 21:05:08 GMT  
 Adding to a combo box or text box through the keyboard
Steve,

Quote:
> I didn't understand the comment about the temporary parameter for
> commandbars being ineffective. With the temporary parameter being used
> should'nt the command bar dissapear the next time word is open?

It *should* but it doesn't ;-)

--
Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.



Fri, 09 Apr 2004 21:43:50 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Limiting Access to Text Boxes, List Boxes and Combo Boxes

2. adding to a combo box or list box

3. Unable to populate text box from combo box

4. Putting a value from a combo box into a text box on a form

5. Filling combo box text box area from data

6. Created Form in Word - Irregular movement of combo boxes, text boxes on scrolling

7. Combo Boxes and Text Boxes

8. Combo Box and Text Box - Plz Help

9. Combo Box and hidden text boxes upon choice

10. HELP Forms, combo boxes, text boxes

11. Problems making a automatic text box when selecting in a combo box

12. Vb 4.0 Problems updating Text Boxes from Combo Box linked to Data Control

 

 
Powered by phpBB® Forum Software