+ Reply to Thread
Results 1 to 4 of 4

Trying to create textboxes in userform with code

Hybrid View

  1. #1
    Registered User
    Join Date
    06-24-2015
    Location
    Vermont
    MS-Off Ver
    2010
    Posts
    50

    Trying to create textboxes in userform with code

    I am trying to use a button in a userform so when I press it it will resize the form and put a new textbox in the form. I am also trying to put some code in for a change event for the new textbox.. this is what I have for code so far.. everything works except for the code for the new textbox. thanks


    Private Sub NewScanbtn_Click()
    
        Dim i As Integer
        Dim strNewName As String
        Dim NewTextBoxTop As Integer
        Dim objNewName As Object
        Dim Line As Integer
        Dim UF As Object
        '--------------------------
        'XXXXXXXXXXXXXXXXXXXXXXXXXX
        '--------------------------
        
      
    i = Me.Counter.Value
    NewTextBoxTop = Me.Height - 90
    strNewName = "Scan" & i
    
    '//Textbox for FailValue, value input in EQDCS
        Set objNewName = ScanTrayForm.Controls.Add("forms.Textbox.1", strNewName, True)
            With objNewName
                .Name = strNewName
                .Height = 23.25
                .Width = 180.05
                .Top = NewTextBoxTop
                .Left = 30
                .Visible = True
            End With
            
        Set UF = ActiveWorkbook.VBProject.VBComponents("ScanForm")
        
            With UF.CodeModule
                Line = .CountOfLines
                .InsertLines Line + 1, _
                 "Private Sub " & objNewName.Name & "_Change()" & Chr(13) & _
                 " msgbox strNewName" & Chr(13) & _
                 "End Sub"
            End With
    
        Me.Height = Me.Height + 30
        Me.NewScanbtn.Top = Me.NewScanbtn.Top + 30
        Me.NewScanbtn.Left = 60
        Me.Counter.Value = Me.Counter.Value + 1
       
    
    End Sub
    Last edited by justlearning123; 10-10-2015 at 11:53 PM.

  2. #2
    Registered User
    Join Date
    06-24-2015
    Location
    Vermont
    MS-Off Ver
    2010
    Posts
    50

    Re: Trying to create textboxes in userform with code

    Any ideas anybody? Thanks

  3. #3
    Registered User
    Join Date
    06-24-2015
    Location
    Vermont
    MS-Off Ver
    2010
    Posts
    50

    Re: Trying to create textboxes in userform with code

    Any ideas anybody? Thanks

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Trying to create textboxes in userform with code

    Why aren't you doing this the normal way? You shouldn't really be adding code at runtime, normally you you a class to create an object that subscribes to the events raised something like http://stackoverflow.com/questions/1...96866#10596866

+ 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. Code to create a new listbox on a userform
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-06-2015, 04:04 PM
  2. Replies: 0
    Last Post: 02-04-2015, 03:46 PM
  3. [SOLVED] Code in userform to be flexible and work with multiple textboxes
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 01-21-2015, 11:04 AM
  4. Need help to get code created Userform textboxes to fire a change event
    By brusk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2013, 12:06 AM
  5. Code to prevent userform from saving duplicates based on 3 textboxes
    By Zygoid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2013, 11:04 AM
  6. Help Populating Textboxes in Userform, With Multipage Userform.
    By mdmorgan24 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2012, 05:29 PM
  7. Replies: 1
    Last Post: 11-29-2010, 06:56 AM

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