I'm working on a database of candidates for council elections, and I have a query that usually returns between 2 and 5 rows of data, (min = 0 max = 15). The data contains 4 fields (given & surname (strings), votes received (int), and is elected (boolean)).
I want to display the query result data on a form, but I want lots of visual cues. For instance, I want the candidate's name to be in a different colour, depending on gender, and whether or not they are elected to be displayed on a toggle button with custom images. Because the number of results can vary, I can't add the needed controls at design-time. I tried to use a subform, but quickly ran into the problem of each subform containing the same instance of a control and therefore not being modifiable on a per-record basis.
I reckoned therefore, I need vba, in order to create the individual controls dynamically. I figured I should be able to iterate through the records in a recordset, creating a label for the names and votes, and a toggle button for whether they are elected, and then doing some calculations on the detail.height property in order to place the controls nicely.
However, when I tried:
vba said
(same when I changed 'Label' to 'TextBox'.) Googling this error returned pages containing text like: "why do you even want to dynamically create a label", and the help page for the error gives me the (entirely familiar) impression that I'm going exactly the wrong way about doing something.
So, how would I do this? As I said, i've got a form. User clicks a couple of combo boxes to define the query's parameters. The query will usually return 2-5 records containing four fields. Because of required visual cues, I can't use a datasheet type view (This was my original solution, but the boss prefers a colourful name to a column showing Male or Female for gender, and a more obvious cue than the small checkbox being ticked or not for the boolean field).
Can someone give me some pointers to either:
mcalex
I want to display the query result data on a form, but I want lots of visual cues. For instance, I want the candidate's name to be in a different colour, depending on gender, and whether or not they are elected to be displayed on a toggle button with custom images. Because the number of results can vary, I can't add the needed controls at design-time. I tried to use a subform, but quickly ran into the problem of each subform containing the same instance of a control and therefore not being modifiable on a per-record basis.
I reckoned therefore, I need vba, in order to create the individual controls dynamically. I figured I should be able to iterate through the records in a recordset, creating a label for the names and votes, and a toggle button for whether they are elected, and then doing some calculations on the detail.height property in order to place the controls nicely.
However, when I tried:
Code:
Dim nameData as Label
nameData = new Label
Code:
Runtime error 429: ActiveX component can't create object.
So, how would I do this? As I said, i've got a form. User clicks a couple of combo boxes to define the query's parameters. The query will usually return 2-5 records containing four fields. Because of required visual cues, I can't use a datasheet type view (This was my original solution, but the boss prefers a colourful name to a column showing Male or Female for gender, and a more obvious cue than the small checkbox being ticked or not for the boolean field).
Can someone give me some pointers to either:
- creating form controls at run-time, or
- showing me what techniques I should be using to solve my problem
mcalex