Text box question

BobJones

Registered User.
Local time
Today, 05:45
Joined
Jun 13, 2006
Messages
42
I have a text box i am using as a search text box. I have a search button which I want to only become enabled when there is text in the search text box. I have tried the following in the textbox on change event but to no avail.

if searchBox.Value = "" then
okBtn.enabled = false
else
okBtn.enabled = true
end if

Also I'm after making it so that if the user doesn't click on the button then they can just press the enter key when in the textbox and it will do the search.
I tried something in the keydown event for the textbox involving vbenterkey (i think) but that didn't work either.

Any help would be greatly appreciated!
 
Put this in the onCurrent event of the form and the afterUpdate of searchBox.

Code:
If isNull(me.searchBox) then 
okBtn.enabled = false
Else
okBtn.enabled = true
End If
 
Cheers, that works when you tab out of the text box or click out of it but i wanted the button to become enabled as i was typing in the search box, thats why I tried it in the onchange event. Any ideas?
 
No, sorry it is not something I have ever wanted to do.
 
BobJones,

I think you are on the right track... in the OnChange event of the textbox just use

Code:
Me.okBtn.Enabled=True

In the LostFocus event of the textbox use

Code:
If IsNull(Me.searchBox) Then
     Me.okBtn.Enabled = False
End If

As for your question about making the search happen by using the Enter Key, from the 'Properties' of the okBtn, click the 'Other' tab, change the 'Default' setting to 'Yes' for that command button.

Scott
 

Users who are viewing this thread

Back
Top Bottom