Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulate all controls by Page Tab

Status
Not open for further replies.

NXMold

Technical User
Jul 22, 2008
104
I have a form with a tab control, and a YES/NO variable for each tab.

When this form opens I wish to lock all the controls on each tab, based on that tabs variable.

Is there a way to step through controls programaticaly based on tab? With each ctl ... on tab? ...
 
I'd use the Tag property of the controls.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya NXMold . . .

I ran a successful simulation on this so here we go.
[ol][li]On each page of the TabCtl put a question mark [blue]?[/blue] [red](no quotations please)[/red] in the [blue]Tag[/blue] property of each control that has a [blue]Locked[/blue] property. Not every object has a locked property, so you'll have to check before setting the tag property. Just keep the properties window open on the [blue]Data[/blue] tab and you'll know as you set focus to each object.[/li]
[li]Make sure your VBA variables are in the declaration section of a module in the modules window. In simulation I used:
Code:
[blue]Option Compare Database
Option Explicit

Public pg0 As Boolean, pg1 As Boolean, pg2 As Boolean[/blue]
Note: Page Index starts at 0.[/li]
[li]In the same module copy/paste the following routine:
Code:
[blue]Public Sub LockTC(TC As TabControl)
   Dim pg As Page, ctl As Control, flg As Boolean
         
   For Each pg In TC.Pages
      flg = Choose(pg.PageIndex + 1, pg0, pg1, pg2)
      
      For Each ctl In pg.Controls
         If ctl.Tag = "?" Then
            ctl.Locked = flg
         End If
      Next
   Next
   
End Sub[/blue]
[/li][/ol]
Finally to call the routine:
[ol][li]From within the form where the tabcontrol resides (mainform or subform):
Code:
[blue]   Call LockTC(Me![purple][b][i]TabControlName[/i][/b][/purple])[/blue]
[/li]
[li]For external control use any proper form/subform referencing to the tabcontrol:
Code:
[blue]   Call LockTC(Forms![purple][b][i]MainFormName[/i][/b][/purple]![purple][b][i]TabControlName[/i][/b][/purple])[/blue]
   or
[blue]   Call LockTC(Forms![purple][b][i]MainFormName[/i][/b][/purple]![purple][b][i]subFormName[/i][/b][/purple].Form![purple][b][i]TabControlName[/i][/b][/purple])[/blue]
[/li][/ol]
As a test set the forms [blue]On Open[/blue] event to:
Code:
[blue]   pg0 = True
   pg1 = True
   pg2 = True[/blue]
Then set the forms [blue]On Load[/blue] event to:
Code:
[blue]   Call LockTC(Me![purple][b][i]TabCtlName[/i][/b][/purple])[/blue]
All controls with question marks in their [blue]Tag[/blue] property should be locked (can't edit).

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
That looks like a gorgeous solution! I'd have never discovered that possiblity, thank you. I'll test it soon.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top