Dan Waters
dwaters at usinternet.com
Sun Jan 29 19:23:43 CST 2006
Hi Arthur, Arthur, I do something like this in one of my applications. There are 4 pages on a 6 page tab control where each of the 4 has a subform control. Within each subform control I can place a specific subform, depending on which Machine number was selected on the Main form. Below is the code to manage this for the first page where different forms can be placed. This code is called by the Form_Current event for the main form, but could be called by other events as well. Perhaps this will give you some ideas. objDCSPageA is the name of the subform control. Note that if cboMachineNumber is null, then the subform becomes not visible, and the page caption becomes and empty string. Hope this helps! Dan --------------------------------------------------------------------------- Private Sub FormatMachineSettingsA() If ErrorTrapping = True Then On Error GoTo EH MblnRunCurrentSub = False If Not IsNull(cboMachineNumber) Then objDCSPageA.Visible = True Select Case cboMachineNumber Case 1 objDCSPageA.SourceObject = "frmDCS1EjectorsSettings" pgeMachineSettingsA.Caption = "1 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine1" Case 2 objDCSPageA.SourceObject = "frmDCS2-3EjectorsSettings" pgeMachineSettingsA.Caption = "2 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine2" Case 3 objDCSPageA.SourceObject = "frmDCS2-3EjectorsSettings" pgeMachineSettingsA.Caption = "3 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine3" Case 4 objDCSPageA.SourceObject = "frmDCS4-5-20EjectorsSettingsA" pgeMachineSettingsA.Caption = "4 - Ejectors 1" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine4" Case 5 objDCSPageA.SourceObject = "frmDCS4-5-20EjectorsSettingsA" pgeMachineSettingsA.Caption = "5 - Ejectors 1" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine5" Case 6 objDCSPageA.SourceObject = "frmDCS6Ejectors" pgeMachineSettingsA.Caption = "6 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine6" Case 8 objDCSPageA.SourceObject = "frmDCS8-9EjectorsSettings" pgeMachineSettingsA.Caption = "8 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine8" Case 9 objDCSPageA.SourceObject = "frmDCS8-9EjectorsSettings" pgeMachineSettingsA.Caption = "9 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine9" Case 10 objDCSPageA.SourceObject = "frmDCS10-14EjectorsSettings" pgeMachineSettingsA.Caption = "10 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine10" Case 11 objDCSPageA.SourceObject = "frmDCS11EjectorsSettings" pgeMachineSettingsA.Caption = "11 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine11" Case 12 objDCSPageA.SourceObject = "frmDCS12EjectorsSettings" pgeMachineSettingsA.Caption = "12 - Ejectors" MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine12" Case 13 objDCSPageA.SourceObject = "frmDCS13EjectorsSettings" pgeMachineSettingsA.Caption = "13 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine13" Case 14 objDCSPageA.SourceObject = "frmDCS10-14EjectorsSettings" pgeMachineSettingsA.Caption = "14 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine14" Case 15 objDCSPageA.SourceObject = "frmDCS15EjectorsSettings" pgeMachineSettingsA.Caption = "15 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine15" Case 16 objDCSPageA.SourceObject = "frmDCS16EjectorsSettings" pgeMachineSettingsA.Caption = "16 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine16" Case 17 objDCSPageA.SourceObject = "frmDCS17EjectorsSettings" pgeMachineSettingsA.Caption = "17 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine17" Case 18 objDCSPageA.SourceObject = "frmDCS18EjectorsSettings" pgeMachineSettingsA.Caption = "18 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine18" Case 19 objDCSPageA.SourceObject = "frmDCS19EjectorsSettings" pgeMachineSettingsA.Caption = "19 - Ejectors" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine19" Case 20 objDCSPageA.SourceObject = "frmDCS4-5-20EjectorsSettingsA" pgeMachineSettingsA.Caption = "20 - Ejectors 1" objDCSPageA.Visible = True MblnRunCurrentSub = True objDCSPageA.Form.RecordSource = "tblDCSMachine20" End Select Else objDCSPageA.SourceObject = "" objDCSPageA.Visible = False pgeMachineSettingsA.Caption = " " End If Exit Sub EH: Application.Echo True Call GlobalErrors(txtDCSID, Err.Number, Err.Description, Me.Name, "FormatMachineSettingsA") End Sub ---------------------------------------------------------------------------- -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Arthur Fuller Sent: Sunday, January 29, 2006 5:34 PM To: 'Access Developers discussion and problem solving' Subject: [AccessD] Switch tab pages based on an AfterUpdate event 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 -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com