Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toolbar Command Can't Recognize Textbox Value 1

Status
Not open for further replies.

Marryp

Technical User
May 28, 2001
129
CA
I have a custom toolbar and one of the command buttons on the toolbar is to check the values of the controls in the form such as textbox, combo box, checkbox, listbox by calling a function. All the controls' value can be identified except the textbox. I tried to use a command button on the form and use the same function and it can read the value in the textbox. So why when I use the toolbar it cannot see the value of a textbox? IS there any workaround?

Thanks. I hope you guys can help one more time.
 
You should be able to read that value...

Is your function using language that should be able to read the value... and is it in a place that it should be able to read the value?

So long as the form is open, using the Forms collection should get you the value:

Forms!YourForm.txtBox

HTH
 
The code looks like this:
Code works on a regular command button but not in the event of a toolbar button
--------------------------

'ctrlCriteria is a global variable

For Each ctrlCriteria In Me
If ctrlCriteria.Tag = "Criteria" And (ctrlCriteria.ControlType = acTextBox Or ctrlCriteria.ControlType = acComboBox) Then
If ctrlCriteria <> Null Or Not IsNull(ctrlCriteria) Then
If ctrlCriteria.Name = "cboEmpOperator" Or ctrlCriteria.Name = "cboOpportunityStatus" Then
'Do nothing
Else
Call f_BuildQuery(ctrlCriteria)
End If
End If
ElseIf ctrlCriteria.Tag = "Criteria" And ctrlCriteria.ControlType = acOptionGroup Then
If ctrlCriteria = Null Or IsNull(ctrlCriteria) Then
'Do nothing
Else
Call f_BuildQuery(ctrlCriteria)
End If
ElseIf ctrlCriteria.Tag = "Criteria" And ctrlCriteria.ControlType = acCheckBox Then
If ctrlCriteria = True Then
Call f_BuildQuery(ctrlCriteria)
End If
ElseIf ctrlCriteria.Tag = "Criteria" And ctrlCriteria.ControlType = acListBox Then
If ctrlCriteria.ItemsSelected.Count = 0 Then
'Do nothing
Else
Call f_BuildQuery(ctrlCriteria)
End If
End If
Next ctrlCriteria
 
There is no "Me" object for toolbars.

Change "Me" to whatever form you are working with:

For Each ctrlCriteria In [Forms]![YourForm]


HTH
 
Hi Rubbernilly my initial code works fine. Me is the same as the Forms!YourForm. However, I figured out the problem and it is the focus of the textbox. If I move the focus on the next control the search will find it. Only after the focus is moved to the next control that the toolbar button command will recognize the value of the textbox.

Is there a way that after entering something in the textbox and then hitting the button on the toolbar it will recognize the value of the textbox without moving to the next control?

Thanks. I hope somebody can help
 
Me" is an object specific variable, and is only the same as Forms!YourForm in the module for YourForm. If "Me" works, then your code has to be in the same module as the form you are working with. Your button must be calling a function contained in the form's module.

A button on the form works because you commit the value to the control be leaving it, whereas a toolbar button does not change your focus.

I don't think there is a way to get at the pre-update text of a textbox except from within the textbox itself (through the BeforeUpdate event).

What you can do is to set the focus to something else and then return to the previous control. The catch is, you want to set the focus to something that itself won't cause this problem, because if you set the focus to a textbox and you happen to be on the textbox, then you won't have updated the .Value property. I'd suggest a command button.

Me.cmdSomeButton.SetFocus
Screen.PreviousControl.SetFocus

Those two lines should take care of the difficulty, even if it isn't a very elegant solution.

 
Thank you for the insight rubbernilly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top