PDA

View Full Version : [SOLVED] VBA - Disable/ activate command button depending on Text box value



torquil
05-08-2020, 02:36 PM
Hi everyone,
I am trying to get a userform to automatically disable a command button if the value of a textbox does not apear in a range.
Currently I have the following:


'check if typed client name is a valid client
Dim TypedName As Range
Set TypedName = Sheets("Clients").Range("A:A").Find(What = tbClientName.Value, LookIn:=xlValues, Lookat:=xlWhole)
If Not TypedName Is Nothing Then
cbLoaddata.Enabled = True
Else
cbLoaddata.Enabled = False
End If


This seems only to diable the the button and i cant seem to work out why its the case.
for context I have a textbox wehre user can type in a client name, a dropdown box apears below and they can click on the name or continue to type. but this allows them to type a name that isnt a client and i need to either prevent this and stop them being able to click on the command button on the userform.

ANy pointers ?

paulked
05-08-2020, 02:56 PM
There is a colon missing after What (should be What:=tbClientName.Value). Worked for me after that.

Be aware! Use a range that is full of data otherwise a blank in the textbox wiill enable the button! "A:A" is unlikely full of names :whistle:

torquil
05-14-2020, 02:57 AM
Thank you paulked, seriously helped (sorry for the delayed recognision).

paulked
05-14-2020, 04:02 AM
No worries, glad to have helped :thumb