"Tedmond" wrote:
Sorry, yours is in VB verion.
Dim myAccount As Accounts
myAccount = New Accounts
frmMain.Controls.Add(myAccount)
"Tedmond" wrote:
private Accounts myAccount;
myAccount = new Accounts();
frmMain.controls.Add(myAccount);
This shouldn't have any problem.
Tedmond
"Dave" wrote:
If I have a name of a User Control in my project, how can I set an Object to
that User Control?
ie;
I have a User Control, called "Accounts" in my project
I tried the following code
strUserControlName = "Accounts"
frmMain.Controls.Add(strUserControlName)
But, of course, the above code doesn't work, because the second line of code
wants a User Control parameter, not a string parameter.
so, I need to do something like this:
dim objUserControl as UserControl
set objUserControl = UserControl(strUserControlName)
How do I do this? Your help would be appreciated.
Dave
While that will work, the problem is, Tedmond, I have about 30 different
user controls that the user can choose from. The thing I'm trying to avoid is
setting up a Select statement with 30 choices in it. What I'm trying to find
is a way, based on a string containing the exact name of the user control, to
generate the form.controls.add(usercontrol) statement out of it.
I need something like:
dim gUserControl as UserControl
gUserControl = MyProject.Component(StringNameOfUserControl)
Form.Controls.Add(gUserControl)
But, I need some correct syntax for that middle line of code. That's what I
don't know how to do.