Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding control at run-time

Status
Not open for further replies.

ivoef

Programmer
May 8, 2002
27
0
0
CZ
Hi,

does anybody know how to add a control to form using VBA code? I know about CreateControl function but I can't switch to the desing mode of the form.

Thanks
 
You'd need to open the form in DESIGN mode to add the control, SAVE that change, and then re-open the form in FORM VIEW (e.g., standard) mode.

Depending on what you really want to do, it may be easier to add the control normally, make it invisible, and make it visible when the situation warrants it. Much easier.

How many of you believe in telekinesis? Raise my hand...
Another free Access forum:
More Access stuff at
 
Actually Im trying to show creosstab query in subform datasheet. The main problem is the crosstab query can have different number of columns in runtime. Then if I use form in the datasheet view it must have all controls asociated with fields in it when I open it. But I can find out the number of columns only when I open the form.

The other way to have is hidding columns in datasheet view but it has two drawback:

1) I have to create all controlls on form (but I don't know how many I will need it)
2) The user can accidentaly change the size of hidden column and display it

Ivo
 
Hi Ivo!

Jim is right, there is no way to add controls to a form unless it is in design view, even using code it must be in design view. Even if you do not know in advance how many controls you will need to display your query, maybe you can figure out some sort of maximum and use Jim's idea above about hidden controls. You can set the controlsource of the different controls to match the fields that were returned. Alternatively, you can create a form in code and then add the controls you need before displaying it.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Hi Jeff & Jim,

thank you for your replies. Recently I have found out the main constraint in using design view and CreateControl: It doesn't work in compiled MDE database. So I had to give up that idea. Now I do the job by having fixed number of existing controls and hiding appropriate columns in datasheet view. It works fine except of the possibility of resizing the hidden columns. Do you have any idea how to disable column resizing in datasheet view?

ivo
 
Hi Jim,

good idea. Thanks.

Ivo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top