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!

GotFocus vs Click Event 1

Status
Not open for further replies.

GoatieEddie

Technical User
Nov 3, 2003
177
CA
Hi All,

I have a listbox on a Form and the listbox is called AllProducts. This code works fine and gives me the desired effect:

Private Sub AllProducts_Click()
RemoveButton.Enabled = True
ChangeButton.Enabled = True
End Sub

However, when the user clicks on another part of the form (a text box for example) I want to disable the two buttons above. I thought this would work:

Private Sub AllProducts_LostFocus()
RemoveButton.Enabled = False
ChangeButton.Enabled = False
End Sub

but it doesn't! Also, I noticed that AllProducts_GotFocus() doesn't run when someone clicks on the ListBox.

Clearly I am getting confused on how to trap the event so if someone could help and put an end to my misery then it would be most appreciated. In summary, what event do I run when a listbox loses "focus"?

many thanks,

GE
 
At least on my side (Excel 2000), controls on userforms don't support gotfocus and lostfocus events. But they do support the Exit event, which will suit your need just fine, I think.


Rob
[flowerface]
 
Thanks Rob. Star for you. for others benefit, the full use of Exit is

Private Sub LB_AllProducts_Exit(ByVal cancel As MSForms.ReturnBoolean)
 
Rob,
Have encountered a problem. Because the listBox Exit event runs before the button click event of the button, the button becomes disabled before its event runs. Any ideas?
 
Hmmm - it's got me stumped, for now. Only thing I can think of, ugly as it sounds, is to disable the buttons in the enter/click events for all other controls on the form. Somebody else hopefully will have a better suggestion.


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top