Solved

Run-time creation of controls

Posted on 1998-08-21
1
131 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

862 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now