Results 1 to 2 of 2

Dynamically set the property of a TextBox

Threaded View

  1. #1
    Registered User
    Join Date
    07-20-2019
    Location
    North Pole
    MS-Off Ver
    2016
    Posts
    3

    Dynamically set the property of a TextBox

    I have a Worksheet with the names of 34 different TextBox's in column 4. In column 5 I have the names of various colors. In column 6 I have the name of a Sub, for example
    tbxCat1 vbYellow TextBoxSettings1
    tbxCat2 vbCyan TextBoxSettings1 <==========There are 6 different TextBoxSettings Subs
    etc.
    I read all of these into two arrays:
    Dim tbxName() As String
    Dim tbxColor() As String
    Dim tbxSubs() As String
    Dim N As Integer
    At some random point in the program I'll call a subroutine, for example:

    Call TextBoxControl(21)     ' Recomended Retail Price TextBox
    
    Sub TextBoxControl(N As Integer)
    Set MyControl = Me.Controls(tbxName(N))
        Select Case tbxSubs(N)
            Case TextBoxSettings1
                Call TextBoxSettings1(MyControl, "", tbxColor(N))   <=======I get a Run-time error '13' Type mismatch. I've replaced tbxColor(N) with vbYellow, but still get the same error
            Case TextBoxSettings2
              etc. etc.
    End Sub
    
    Sub TextBoxSettings1(ByRef tbx As MSForms.TextBox, tbxValue, tbxColour)
    tbx.Value = tbxValue
    tbx.BackColor = tbxColour
    tbx.ForeColor = vbBlack
    tbx.SpecialEffect = fmSpecialEffectSunken
    tbx.BorderStyle = fmBorderStyleNone
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    I think the error is something to do with "Dim tbxName() As String"
    Can anyone advice?

    Regards

    Joe
    Last edited by 6StringJazzer; 10-01-2019 at 04:03 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Change width of Textbox dynamically
    By naveenmarapaka in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2014, 07:52 AM
  2. Dynamically linking textbox and cell
    By Leeban in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2014, 04:04 PM
  3. [SOLVED] TextBox-self calculating property ?
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-07-2013, 03:25 PM
  4. Set property of TextBox class
    By RUOTAHEL in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-16-2010, 04:49 AM
  5. Get textbox value from custom/dynamically generated form
    By sonyidicula in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-16-2010, 08:52 AM
  6. Set PivotItem.Visible property dynamically
    By drocco in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-01-2008, 12:46 PM
  7. Textbox property change
    By efernandes67 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2008, 07:05 PM

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