CommandBar Help

Adoh

New Member
Joined
Sep 6, 2006
Messages
8
Hi,

This is my first post, and this is probably a simple question

I am trying to create a toolbar which has a commandControlEdit(textfield)
and a commandControlButton(button)

I want a message box to pop up and give the name of the text in the text field.

BUT whenever i click the the button the text dissapears.

and my onAction method cannot capture the text befor it disappears


Can anyone Help
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
Good evening Adoh

I don't believe this is possible.

It's very annoying because the Microsoft knowledge base says that an msoControlEdit box is simply an msoControlComboBox without the dropdown facility, but the user response from this type of control can be captured fairly easily.

Is an msoControlComboBox acceptable?

HTH

DominicB
 

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
Hi Andrew

If you press Enter or Tab before clicking the button, the entry will stick.

...but how do you actually capture it...?

DominicB
 

Adoh

New Member
Joined
Sep 6, 2006
Messages
8
Hi DominicB,

To capture it,
I set the .onaction in the commandcontroledit

to a function i declare and pass the index

here is an example of how i did it:

13 is th id of the textfield
.OnAction = "'IDTables_Find """ & 13 & """'"


Sub IDTables_Find(textfields As Integer)

If textfields = 13 Then
findtext = CommandBars(thisButtonCaption).Controls(textfields).Text
End If


But i still do not know how to get it using the command button


end sub
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
This worked for me:

Code:
Sub AddBar()
    Dim CB As CommandBar
    Dim CBC As CommandBarControl
    Set CB = CommandBars.Add
    With CB
        .Name = "MyBar"
        .Visible = True
        Set CBC = .Controls.Add(msoControlEdit)
        With CBC
            .Tag = "MyEdit"
        End With
        Set CBC = .Controls.Add(msoControlButton)
        With CBC
            .Tag = "MyButton"
            .Style = msoButtonIconAndCaption
            .Caption = "Get Text"
            .OnAction = "GetText"
        End With
    End With
End Sub

Sub GetText()
    MsgBox CommandBars("MyBar").FindControl(Type:=msoControlEdit, Tag:="MyEdit").Text
End Sub
 

Forum statistics

Threads
1,137,300
Messages
5,680,699
Members
419,928
Latest member
dolincasting

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top