Create Controls Real-Time

JaedenRuiner

Registered User.
Local time
Today, 01:25
Joined
Jun 22, 2005
Messages
154
The VBA compiler yelled at me, and I am curious:

Can I create a control on a form real-time? For example an advanced search form, that will use AND/OR expressions to build a query into a subform. Thus, i have a combobox that has the values "";"And";"Or", and when that combo box is selected to equal "and"/"or" i want to create the controls to seach for the next item. (Simple CreateControl(Me.Name, acTextBox...) etc.)
THe compiler said I could only create controls on a form during design time but that seems foolish, (or extremely limited). Is it possible to create a control on the fly in access vba?

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
You must be in design view to add a control. You could create the control and set its visible property to false. Then when the combobox meets the requirements you can change the visible property to true.
 
Search help for CreateControl and CreateReportControl

These methods realy work, but total number (index, count) of inserted controls is low (about 1024) per form. When you delete unused control counter doesn't decrease (stays same) :cool:

I suggest countinuous form instead...
 
Pavel69 said:
These methods realy work, but total number (index, count) of inserted controls is low (about 1024) per form. When you delete unused control counter doesn't decrease (stays same) :cool:

I suggest countinuous form instead...

What do you mean Continuous Form? I mean, I just need a simple dialog form that has a few controls and a button to execute the search.

KeithG said:
You must be in design view to add a control. You could create the control and set its visible property to false. Then when the combobox meets the requirements you can change the visible property to true.

I know I can do this, but the problem is, there are an indeterminate amount of search parameters. I know I'll be querying the table based upon 2 or 3 fields, but there could be 3 search elements, or 5 search elements, it's unknown at design time. If I use the Visibility method, that limits me to a "max" search parameter setup, where I can only search for 5 items at most, instead of allowing for the search to be handled on the fly.

Thanks

Jaeden "Sifo Dyas" al'Raec Ruiner
 
JaedenRuiner said:
What do you mean Continuous Form? I mean, I just need a simple dialog form that has a few controls and a button to execute the search.


Every Access form can be displayed in three basic views. Single form, Continuous form and Datasheet. See properties DefaultView and ViewsAllowed or in form design view pop-up option next to View mode (first from left) button.

I suggest you create table i.e.: QuestBase(id, condition, operator, etc.) and then display it like a Continuous form.
After you collect all data, just run VBA code which pass through all records from QuestBase table and build string with condition you require.
It's much simple than collect data from many generated controls, which in VBA cannot be grouped into array....
 
rather than creating controls at run time, you could have overlaid controls in the same place, and then depending on which you need, hide or show each as necessary. However, there is no need to do this anyway, as you could just change the caption on the button, and then run conditional code within the click event for the button.
 

Users who are viewing this thread

Back
Top Bottom