[AccessD] Switch tab pages based on an AfterUpdate event

Arthur Fuller artful at rogers.com
Sun Jan 29 17:34:04 CST 2006


Assume N pages on tab control. Page 3 depends upon a value entered in Page
2. 
Two questions:
1. How would I refer to the control on page 2 from page 3 (assume that page
3 contains a subform. I don't want to mention the parent specifically but
rather refer to it via the Parent property. This syntax always confuses me.
2. Imagine that I have a value on the main form which enables to you to
specify the number of objects X (which are embedded in this table -- NOT my
choice but I am dealing with an inherited design!)... the original developer
created a bunch of columns named X1a, X1b..., X2a, X2b and so on, up to X4.
There are so many of these that I had to create a subform and plonk all the
X2s... X4s on the subform and use a separate query for the subform. Version
2 of this software is already on the drawing board but while it's in
development I have to deal with the bugs in V. 1.0 and fix them. So...
suppose two tab pages, the first for the most common case, which assumes the
existence of 1 instance of object X, and another tab page which assumes the
existence of more than 1 object X. (Let's not address the intelligence of
this design; I already agree with your objections.) On the first page of the
tabbed form the user tells me how many instances of object X there are. The
answer could be 0...4. 
In the event of zero, I would like to hide two tab pages, the one that
obtains the info for X1 and the other that obtains the info for objects
X2...X4. 
In the event of 1 instance, I want to hide the second tab page and make
visible the first. 
In the event of 2 intances, I want to expose the second tab page and disable
the controls corresponding to X3 and X4.
Ditto 3 instances.
On 4 instances, then everything is enabled. 
So... my alleged scenario is this:
1. Open the form in Add mode and neither tab page is exposed until I obtain
a value for the number of instances. The moment I obtain the number of
instances, I reveal the page(s) described above.
2. Open an existing row and the FormOpen code looks at this value and
decides whether to expose either or both of these tab pages.
I hope that I have described the problem adequately.
The code that I inherited works, sort of, but it is not bulletproof. It lets
you enter nonsensical data (i.e. you can specify there are 2 instances of
object X and then add details about instance 3, which makes no sense; yes, I
could code it ass-backwards and determine how many instances you filled in,
then go back and adjust the "number of instances" control, but IMO this
approach is asinine.
My design principle, wherever possible, is to preclude errors rather than
respond to them. So if the number of instances is 2, you should not be
allowed to enter info about instance 3 or 4. 
You might disagree with this design principle; that is your prerogative; but
it is the one that I try hard to adhere to.
Bit of a sidetrack there, so I will reiterate briefly:
Number of instances declared (either in data-entry or in retrieve is 1: hide
the tab page that exposes instances 2...4.
Number of instances declared is zero (new record or existing record where
instances = zero), hide both pages.
Number of instances > 1, expose both tab pages.
Number of instances = 2, disable the X3 and X4 controls on the second tab
page.
Number of instances = 3, disable the X4 controls.
Number of instances = 4, enable all the controls.

Arthur,
Son of Uther Pendragon,
Defeater of the Saxons,
Lord Over Alllll England, and
King of the Dorks
 





More information about the AccessD mailing list