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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build a Form in the On_Load event

Status
Not open for further replies.

MikeC14081972

Programmer
May 31, 2006
137
GB
Have done a search but found nothing yet.

I have a matrix table and a recordset based on this table.

Is there a way of having a blank form and in the on load event doing the following based on the results of the recordset.

1. Adding a control to the form
2. Bind the control to a field in a table

I have a method whereby all the controls are on the form and I move them and make them either visible or invisible based on the recordset but I'm sure there must be a quicker way.

Thanks
 
I may be wrong on this, but AKAIK you can not do it in that order. You need to put the form into design view in order to add controls. I do not think you can do that from the load event. Building forms dynamically is a pain to get all of the formatting correct so I rarely have the need. But if I remember correctly your code needs to do the following.

1)Open form in design view and hidden
2)Delete old controls not used.
3)Add new controls set controlsource
4Save form
5)Open form in form view

I have done this a few times and found it to be more pain then it is worth. Any reason you need to go this route?

I have seen a couple of robust class modules out there for dynamic forms. Maybe check lebans site.
 
The matrix table holds a record of fields that need to be displayed dependant on the dept ID.

There are a possible 150 fields that could be shown, but in reality not all will be shown.

I could build a different form per dept but was trying to keep it to one form.

Looks like I'll go down the route of one form per dept.
 
If these fields have some kind of grouping, maybe you could group them onto pages of a tab control. Then maybe you could just hide certain pages for certain depts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top