Solved

Run-time creation of controls

Posted on 1998-08-21
1
132 Views
Last Modified: 2010-04-30
 Is it possible to create a control at run-time?
  Say I need to use ListBox control inside *class module* just for maintaining of the sorted list of items.

  If you are familiar with Delphi there this is really simple. You write just this
  someControl := TsomeControl.Create(nil);
where nil is the empty "owner" of someControl (which is normally Form).
After that you set all properties you need and that's it.

  If the answer is positive I will increase points for any
code example.
0
Comment
Question by:dksqrt
1 Comment
 
LVL 1

Accepted Solution

by:
jsuper earned 100 total points
ID: 1430295
Unforunatly, some controls cannot be created at run time, the listbox being one of them.  There is a rather simple workaround though.  Create a form and set it's visible property to false so that it will never display.  Place any controls you need at run time on this form.  For example, I usually name the form frmObjects.  Then, in your class, you redefine your objects as being the objects on the hidden form.  For example...

Options Explicit

Dim VList as ListBox

Private Sub Class_Initialize()
   Set vList = frmObjects.Listbox1
   ...
End Sub

Now these controls can be handled as if you had just created them in the class.   Hope that helps.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question