jwcolby
jwcolby at colbyconsulting.com
Tue Mar 11 06:19:20 CDT 2008
Darryl The following code is what I used in the LWS you have seen me mention. The tab controls themselves do not have a click event, and while the tab form does, it does not fire when you click on a tab, but rather when you click on some part of the tab control itself - mostly useless IMHO. So we use the change event which does fire when you click a tab page. This code assumes that ONLY subforms are on the tabs, if you have other controls then you will need to do a check that the control selected is in fact a subform. pgOld.Controls(0).SourceObject = "" I pull the code out into a function because I manually load the main form on the main tab. I also UNLOAD the form on the tab clicked off of. I do this for a variety of reasons including the fact that it makes things faster and uses less resources. Enjoy, '--------------------------------------------------------------------------- ------------ ' Procedure : mLoadsubform ' Author : jwcolby ' Date : 3/6/2008 ' Purpose : Implements Just-In-Time subforms '--------------------------------------------------------------------------- ------------ ' Private Function mLoadsubform() Dim pgNew As Page Dim pgOld As Page Static intOldPageIndex As Integer On Error GoTo mLoadsubform_Error ' 'Get the currently selected page Set pgNew = tabLWSCtl.Pages(tabLWSCtl.Value) Set pgOld = tabLWSCtl.Pages(intOldPageIndex) ' 'Unload the old page's subform ' pgOld.Controls(0).SourceObject = "" ' 'Move the tag into the source object. This will cause the subform to load 'assuming that the control is a subform control of course pgNew.Controls(0).SourceObject = pgNew.Controls(0).Tag intOldPageIndex = tabLWSCtl.Value mLoadsubform_Exit: On Error Resume Next Exit Function mLoadsubform_Error: Select Case Err Case 0 '.insert Errors you wish to ignore here Resume Next Case Else '.All other errors will trap Beep LogErr Err.Number, Err.Description, Erl, Me.Name, "mLoadsubform" Resume mLoadsubform_Exit End Select Resume 0 '.FOR TROUBLESHOOTING End Function '--------------------------------------------------------------------------- ------------ ' Procedure : tabLWSCtl_Change ' Author : jwcolby ' Date : 3/6/2008 ' Purpose : Implements Just-In-Time subforms '--------------------------------------------------------------------------- ------------ ' Private Sub tabLWSCtl_Change() mLoadsubform tabLWSCtl_Change_Exit: On Error Resume Next Exit Sub tabLWSCtl_Change_Error: Select Case Err Case 0 '.insert Errors you wish to ignore here Resume Next Case Else '.All other errors will trap Beep LogErr Err.Number, Err.Description, Erl, Me.Name, "tabLWSCtl_Change" Resume tabLWSCtl_Change_Exit End Select Resume 0 '.FOR TROUBLESHOOTING End Sub John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Darryl Collins Sent: Tuesday, March 11, 2008 12:24 AM To: Access Developers discussion and problem solving Subject: [AccessD] TabControlSheet Page Event? Hey all, I am stuck on with this, It is probably easy but been up since 4am (it is now 3:20pm) so I am not the sharpest tool in the shed right now! I have a form with sheet tabs, currently when a user opens the form it is populating all the tabs with data, but this seems a lot of overhead as some users will only look at one or two of the Tab pages. I wanted to capture when a user click on the tab page so I can call some VBA that will load the sub forms for that page only. I have the code to populate the sheet tabs etc, but I cannot seem to capture the "click on page tab" event at all. I can get "Click on TabControlSheet" but that is for the whole sheet and/or other such unhelpful combos of events. I thought this would be simple, but maybe I am wrong? '------------------------------------------------ ' Something like: Private Sub TabControlSheet.Pages(2)_Click() ' Then call the modules I want End sub '------------------------------------------------ would be great, but that doesn't seem to be an option. Any advice? cheers Darryl. This email and any attachments may contain privileged and confidential information and are intended for the named addressee only. If you have received this e-mail in error, please notify the sender and delete this e-mail immediately. Any confidentiality, privilege or copyright is not waived or lost because this e-mail has been sent to you in error. It is your responsibility to check this e-mail and any attachments for viruses. No warranty is made that this material is free from computer virus or any other defect or error. Any loss/damage incurred by using this material is not the sender's responsibility. The sender's entire liability will be limited to resupplying the material. -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com