+ Reply to Thread
Results 1 to 4 of 4

How to enable textbox when a specific item in combobox is selected?

  1. #1
    Registered User
    Join Date
    04-12-2021
    Location
    Singapore
    MS-Off Ver
    Office 365
    Posts
    8

    Question How to enable textbox when a specific item in combobox is selected?

    I created a userform, which contains a combobox (Process A, B, C, and D) and two textboxes; the name of the combobox is Process whereas the names of the textboxes are P_Ini and P_Fi

    I would like the textboxes to be enabled (they are disabled by default) when Process A is selected. When I tested the codes, the textboxes remained disabled. Not sure what went wrong here, so I would appreciate if anyone could advise on this.

    [code]
    Sub Process_Change()

    'Textboxes are greyed out by default

    If Process = "Process A" Then
    P_Ini.Enabled = True
    P_Fi.Enabled = True
    P_Ini.BackColor = &H80000005 'colour code for white
    P_Fi.BackColor = &H80000005
    Else
    P_Ini.Enabled = False
    P_Fi.Enabled = False
    End If

    'PURPOSE: Prevent user from entering non-numerical values in userform textbox

    'Allow for negative numbers

    If Not IsNumeric(P_Ini.Value) And P_Ini <> "-" And P_Ini <> "" Then
    P_Ini = Left(P_Ini, Len(P_Ini) - 1)
    MsgBox "Only numbers allowed"
    Cancel = True
    P_Ini.Value = ""
    End If

    If Not IsNumeric(P_Fi.Value) And P_Fi <> "-" And P_Fi <> "" Then
    P_Fi = Left(P_Fi, Len(P_Fi) - 1)
    MsgBox "Only numbers allowed"
    Cancel = True
    P_Fi.Value = ""
    End If
    End Sub
    [\code]
    Last edited by Wilheim; 05-20-2021 at 04:39 AM.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: How to enable textbox when a specific item in combobox is selected?

    What is the purpose of setting the backcolour, normally it is white when enabled.

  3. #3
    Registered User
    Join Date
    04-12-2021
    Location
    Singapore
    MS-Off Ver
    Office 365
    Posts
    8

    Re: How to enable textbox when a specific item in combobox is selected?

    Since the textboxes are disabled by default unless Process A in the combobox is selected, I used dark grey as the backcolour so it can serve as a visual indication that the fields are not available for the users to fill in.

    Dark grey textbox (default) --> disabled
    White textbox --> enabled when Process A is selected

    Hope that clarifies!

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: How to enable textbox when a specific item in combobox is selected?

    you are testing the state "Filtration" - how is the variable 'Process' assigned.
    Far easier to give a definitive answer from an actual workbook.
    see big yellow banner - how to upload your workbook - remember to desensitise any confidential data.
    Also please satisfy forum rule# 2 - enclose your code with code tags before moderators smack your knuckles

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 01-18-2020, 12:44 AM
  2. [SOLVED] Match Combobox with textbox then enable password: HOW TO?
    By poizones in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 11-08-2018, 03:58 AM
  3. [SOLVED] enable/disable combobox based on textbox entry
    By bqheng in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-05-2017, 11:53 AM
  4. Combobox enable textbox
    By jpernice in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-24-2015, 09:16 PM
  5. selecting an item in combobox, the item does not get selected
    By AVM in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-14-2014, 05:14 AM
  6. Replies: 3
    Last Post: 04-02-2013, 06:02 PM
  7. Combobox: How to determine the location of the selected item if combobox has rowsource
    By ahsanzafar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2012, 03:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1