469,903 Members | 1,808 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Text in toolbar text field not committed before clicking toolbar command button

I use the following code to create text edit fields and command buttons
in my toolbars:

Function CreateToolbarObject(myObjectType as integer)

Dim newObject

Select Case myObjectType
Case 1 'text
Set newObject =
CommandBars(myToolbarName).Controls.Add(Type:=msoC ontrolEdit)
Case 2 'command button
Set newObject =
CommandBars(myToolbarName).Controls.Add(Type:=msoC ontrolButton)
Case 3 'popup
Set newObject =
CommandBars(myToolbarName).Controls.Add(Type:=msoC ontrolPopup)
Case 4 'combobox
Set newObject =
CommandBars(myToolbarName).Controls.Add(Type:=msoC ontrolComboBox)
End Select

End Function

Works great
(You must first set the reference to the MSOffice X.0 Object Library)
I use the following code to make things happen after entering text in a
toolbar edit field ("myToolbarEditFieldName") and then clicking a
command button on the same toolbar:
Function DoSomethingSnazzyFromToolbar()
Dim objBar As Object, objCbo As Object, _
myString As String

Set objBar = Application.CommandBars("myToolbarName")

Set objCbo = objBar.Controls("myToolbarEditFieldName")

myString = objCbo.Text
myString = Trim(myString)

If Len(myString) > 0 Then

'run some spiffy code here

end if

myExit:
On Error Resume Next
objCbo.Text = ""
Set objCbo = Nothing
Set objBar = Nothing
Exit Function
myErr:
MsgBox Err.Number & " " & Err.Description
Resume myExit
End Function
The problem is when I click the toolbar command button, the value of
the toolbar edit field is not committed and myString = objCbo.Text
returns a null value.

It only works if I hit the enter or tab keys before clicking the
toolbar command button.

Is there an equivalent of a "refresh" for the toolbar or some code fix
that will solve this?

Any help is appreciated.
lq

Nov 13 '05 #1
0 1593

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Tony Cooke | last post: by
9 posts views Thread by lkrubner | last post: by
8 posts views Thread by VB Programmer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.