Solved

Run-time creation of controls

Posted on 1998-08-21
1
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

690 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