Consulting

Results 1 to 4 of 4

Thread: VBA - Disable/ activate command button depending on Text box value

  1. #1

    VBA - Disable/ activate command button depending on Text box value

    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 ?

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    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
    Semper in excretia sumus; solum profundum variat.

  3. #3
    Thank you paulked, seriously helped (sorry for the delayed recognision).

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    No worries, glad to have helped
    Semper in excretia sumus; solum profundum variat.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •