?
Solved

Run-time creation of controls

Posted on 1998-08-21
1
Medium Priority
?
135 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 300 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

Independent Software Vendors: 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

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