Data display (1 Viewer)

mcalex

Registered User.
Local time
Tomorrow, 04:54
Joined
Jun 18, 2009
Messages
141
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:
Code:
Dim nameData as Label
nameData = new Label
vba said
Code:
Runtime error 429: ActiveX component can't create object.
(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:
  • creating form controls at run-time, or
  • showing me what techniques I should be using to solve my problem
many thanks in advance
mcalex
 

mcalex

Registered User.
Local time
Tomorrow, 04:54
Joined
Jun 18, 2009
Messages
141
hmmmmm
ok, howsabout i create all the controls (ie 15 each of txtbox for name, 15 each of txtbox for votes, 15 each of togglebutton for elected), giving them names like name0, name1, ..., votes0, votes1, ..., elected0, elected1, .... and setting .visible to false at design time.

Then at runtime I can iterate through a query's recordset and insert the data into each control and turn visibility on ...
except how do i reference eg names4 to make it visible?

Code:
names & rst.AbsolutePosition.Visible = True
doesn't work.

Maybe a 15 branch select case statement? yukkk

does no replies mean i'm doing something dumb, or just way left of centre ... ? :confused: Either way, any pointers will be gratefully accepted.

cheers
 
Last edited:

Users who are viewing this thread

Top Bottom