Monday, 18 February 2013

Rep by Pop: Re-drawing the USA

Despite their differences in governmental style, the USA and Canada share one political fact: the glaring inequality of voting regions based on geography rather than population. Such a scheme may have made sense  two or three centuries back, but as our societies grow increasingly urban, the result is that the vote of a citizen in a sparsely populated region vastly outweighs the vote of a voter who lives in a large city or densely populated area.

One possible solution has been proposed by Neil Freeman, an artist and urban planner who, in an article posted at his site, proposes a radical re-drawing of the map of the USA (Electoral College Reform (fifty states with equal population). Mr. Freeman was careful to preserve the number of states, although he did rename them all. For a refreshing look at a possible America, I urge you to visit his site.

I for one think this is a great idea, albeit extremely unlikely to occur. I would like to apply the same principle to the map of Canada, and shall do some work on this soon. In Canada we have what we call Ridings, which are regions that elect a Member of Parliament. I have the populations of all Ridings in Canada; I just have to average them and redraw the boundaries.

TreeViews -- A Powerful Yet Simple Alternative


Treeviews – A Powerful  Alternative
I have written previously on using the TreeView within Access (Using TreeViews). There are a number of good reasons to use TreeViews – perhaps highest among them is that they are everywhere within the Windows UI, with the result that virtually everyone knows how to use them.

TreeViews are not especially easy to program. Further, they have a number of limitations. However, I have stumbled upon a powerful alternative that delivers an interface much more to my liking. Not only that: it’s very powerful and flexible, and delivers precisely the amount of control that I want. Best of all, it’s dead-simple to create – so simple, in fact, that I wonder why it took me so long to think of it.
The following example was developed in Access 2007 and will work in later versions. I have not tested it in previous versions.

Figure 1: Three-Level "TreeView"

This looks a lot like a formless browse of the parent table. Access does this automatically when you have defined relationships among your tables. However, it happens automatically only when any given parent table has exactly one child table. When two or more child tables exist, Access can’t determine which one to use, and therefore prompts you for the table to use. And unfortunately, once you've made that decision, you're stuck with it: every time you open the parent table, you get the same child you originally selected. 

Although Figure 1 looks a lot like a formless browse, it is actually a series of forms created in DataSheet style, then nested. If you wish, you can even create normal forms for each level, and open them on double-click anywhere within the row of interest. (In this app, I did not do that, because the target users are all very comfortable in Excel, and used to the "spreadsheet" format depicted above.)

By using DataSheet forms rather than simple table-browses, you get complete control  over columns, events, validations, lookups and so on that are available in a form. In this example, I chose to freeze the first two or three columns at each level, so the user never loses track of which row is active.

To create such a “treeview” form, follow these steps:
1. Decide the hierarchy of tables or queries you want to display.
2. Starting at the bottom of the tree, create a datasheet form for each level. This command is hidden a little bit on the Create ribbon. Figure 2 shows where it is.



Figure 2: Create a DataSheet form.
3. Starting one level above the bottom, add a subform. In this example, we create three DataSheet forms and save them. (Call them DS1, DS2 and DS3.) Then we add a subform to DS2 , selecting DS3 as the subform to add. Then we add a subform to DS1, selecting DS2 as the subform. Presto! Your hierarchical form is ready to go.
4. Customize each form to suit your requirements. Write code for events, add validations, combo-boxes. Do everything you would do to a standard form that displays only one record at a time. Decide whether it would be useful to freeze one or more of the columns.


That’s all there is to this simple trick. When I presented the app to the users, they were wowed. With their approval, I used this technique throughout the whole app, wherever hierarchies were involved.