Consulting

Results 1 to 5 of 5

Thread: Copying a Textbox and Combobox at runtime

  1. #1
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location

    Copying a Textbox and Combobox at runtime

    Is it possible to dynamically copy a textbox or a combobox at runtime?

    I have a series of textboxes on a form for user input, and thats fine if they only need to put in data for one item.
    However at the time of programming, I don't know how many items the user will need to include data for.

    What I was thinking was if when the code starts, the user inputs the number of items.

    Can VBA copy the textboxes (named unit01, date01, time01) and the combobox (named combo01) for each additional item, and rename the textboxes and combobox as unitxx, datexx, timexx comboxx where xx refers to each item.
    So if there were 4 items, I would end up with 16 boxes in all (unit01, unit02, unit03, unit04, date01, date02, date03, date04, time01, time02, time03, time04, combo01, combo02, combo03, combo04)

    Is this possible, or is it a can of worms?
    Also when the data has been collated and used, and the form closed down, it would need to revert to just one row of textboxes and combobox (still called unit01 etc etc)

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This has been stated many times, and it is just as true today as it was then.

    It is far better to create the most controls that you might need at design time, and hide the ones not in use until they are needed.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location
    Hi Xld,
    I appreciate that, but the problem is I don't know how many controls I'm going to need, as it will be used much like a datasheet in access. Is it possible to recreate that on an excel form?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is possible, but not easy. And you have to have sopme code to process them, validate the entry and so on, which is even harder.

    Surely, you have a limit. Otherwise, how big will the form get?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location
    Yeah, there is probably a maximum, of about 30 items. So I think I'll head your advice, and create 30 rows of each item, and name them as indicated above. I can then still run loops to populate the date, and show and hide each of the rows.

    Thanks for your advice.

Posting Permissions

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