+ Reply to Thread
Results 1 to 8 of 8

Insert a Textbox in a Frame during runtime

  1. #1
    Registered User
    Join Date
    01-13-2007
    Posts
    9

    Post Insert a Textbox in a Frame during runtime

    I´m adding textboxs in runtime mode. I need to insert those controls in a specific Frame.
    I search the web and only found a solution for VB6, but it doesn´t apply to VBA.
    I´m using Excel 2003.

    Code:

    Sub AddTextbox()

    Dim Txt As Control
    set Txt = Me.Controls.Add("Forms.TextBox.1")
    'The new Textbox is added in the Userform
    'I need that the new textbox to be inserted into the Frame1.

    End Sub

    The "Container" method doesn´t apply here (it does in VB6)
    Example: set me.txt.container=me.Frame1

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Well ... ya know, VBA is only a subset of VB, and a different subset for each version.

    You do not say, and the code does not inform, if these are Controls added to a Form or to a Worksheet. (i.e., who is "Me"?)

    If a Worksheet, there is no "group" object among the ActiveX controls; in which case you would need to use the older (Excel5) controls in order to have a "group" object. If you are going that route, see the Forms toolbar. There is not a lot of documentation of these older Controls, but for certain purposes they work very well.

  3. #3
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203

    Sorry ... ignore previous post

    I take it back. The comments in your code make it clear you are referring to a UserForm. Sorry about that. Try this:

    Please Login or Register  to view this content.
    If you do not already have a frame, then:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-13-2007
    Posts
    9

    Thanks!

    It works thanks!

    Before I posted the thread I tryed to as similar solution.

    I´m making a custom "autofilter" utiliy. I´m adding Texbox that allow the user to insert many criterias.

    Look at this and tell me what is wrong:

    sub AddTexbox()

    dim Txt as control
    dim Fr as Frame
    dim ctrl as control

    set Fr =me.Frame1

    for each ctrl in me.controls
    if typename(ctrl)="Frame" then

    'Here goes another piece of code, because I have many Frames and not all are used to add new textboxs

    set Txt=me.ctrl.controls.add("Forms.Textbox.1")
    'This code fails, I guess that "ctrl" is a frame at this point

    'This one works
    'set Txt=me.Fr.controls.add("Forms.Textbox.1")
    'I need the first line because if not, I repeat the code for every single frame. Can you find the error?

    end if

    next ctrl

    end sub

  5. #5
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    What you are attempting sounds ingenious. I would love to see it when it is finished.

    About this problem line of code:
    Please Login or Register  to view this content.
    I think the problem is "Me". Since ctrl is already defined as an object, "Me" is not necessary, and possibly is the source of the problem. Try it without me.

  6. #6
    Registered User
    Join Date
    01-13-2007
    Posts
    9
    Quote Originally Posted by MSP77079
    What you are attempting sounds ingenious. I would love to see it when it is finished.

    About this problem line of code:
    Please Login or Register  to view this content.
    I think the problem is "Me". Since ctrl is already defined as an object, "Me" is not necessary, and possibly is the source of the problem. Try it without me.
    I will send it as soon as I finished. It´s almost finished by now, I'm working on details.

  7. #7
    Registered User
    Join Date
    01-13-2007
    Posts
    9

    Right again

    It was the "me" as you said!

  8. #8
    Registered User
    Join Date
    01-13-2007
    Posts
    9

    Demo of custom autofilter

    I´m posting a demo of my macro.

    It´s a type of custom "autofilter", but it´s completely independent of the Excel Autofilter. My method doesn´t hide cells, instead of it, it copies the data to another sheet.

    The advantage of my tool is that it allows the user to filter many criterias (excel´s sautofilter only two). It´s also has a tool that gives you stats of the current filtered data. It´s slower than Excel Autofilter (impossible to beat with VBA).

    I´m working on several aspects by now, any suggestions will help.

    PS: all comments are written in spanish, sorry! I´m a newbie on this, you may find many things that can be done better.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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