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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unlock all controls on Page 1 of Tab Control 2

Status
Not open for further replies.

peryan77

Programmer
May 7, 2004
41
US
I want to unlock about 12 controls (textbox and combo) on page1 of a tab control. What is the best way to do this?
 
Peryan,

I'm not sure if you can programmatically sort out which control is on which tab page (someone more sophistcated might have a method) , but you can name them so that you can control the properties of only specific groups of controls - like the ones in a given part of a form, or of a given type.

Name all controls on your tab form with which tab page they are on and then use a loop to work with them.

Using names like:
Txt1TP1 - Txt1 on Tab Page 1
Txt2TP1 - Txt2 on Tab Page 1
Cbo1TP1 - Combo1 on Tab Page 1
Cbo2TP2 - Combo2on Tab Page 1

Then you could use code something vaguely like:

Private Sub ToggleTP1Enabled()

Dim ctl As Control
For Each ctl In me.Controls
Select Case ctl.ControlType
Case acComboBox, acListBox, acTextBox
If right(ctl.Name,3) = TP1 Then
if ctl.enabled = true then
ctl.enabled = false
else
ctl.enabled = true
' toggling the enabled property
End If

End If

End Select
Next ctl
End Sub

Warning ! Warning! - typed just in the web window. Not in VBA window. Definitely not tested....!

Best,

C
 
I didn't think it was possible either, I really rather stay away from renaming all those controls, it makes it harder to go back and recode and errors when you lose track which field = what control.

I presume you can use TAG property and just embedded another if statement in the code? I will test this out.

Access really needs to fix this problem with the tab control.
 
If you don't want to use a naming convention for your controls, then you could create an array and each element of the array contains the name of a control. Then just loop thru your controls on the form and if their name matches a name in the array, unlock it.
 
I suggest that you drop a button on a form, and in the OnClick event for that button drop in the following code:
Code:
Private Sub cmdCntlList_Click()

   Dim lCtl As Control
   
   For Each lCtl In Me.Controls
      Debug.Print lCtl.Name, lCtl.Parent.Name
   Next
   
End Sub
Look at the results in the Immediate window, and you'll see that you may be that this is not a difficult process. Based on the name of your controls, a loop something like the following:
Code:
For Each lCtl In Me.Controls
   If lCtl.Parent.Name = "<TabPageName>" Then
      lCtl.Enabled = True
   End If
Next
Debug.Print lCtl.Name, lCtl.Parent.Name
Next




Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Great suggestion Cajun, works great on text, combo & Toggle buttons, but still somewhat ambivalent, on labels. Which, after all, may be incidental to Perryan77's needs.
Great suggestion!
 
The challenge you bring forth dboulos, is probably that some labels are attached to controls, and some are detached.

The parent control of an attached control, is the control it is attached too, so CajunCenturions suggested code will not address those directly, but thru toggling their parent controls, they will inherit the parent controls property.

Labels doesn't have an enabled property, so the detached labels, if present, will have to be excused, for instance by adding another criteria, for instance:

[tt]if lCtl.Controltype<>acLabel then[/tt]

Some more "control looping" tips in this faq faq702-5010.

Roy-Vidar
 
ooops, meant ambiguous...
Another good suggestion, RoyVidar.
It seems, one would have to be aware of the control name, in order to ascertain which attached label resided with it, on the tab page. Which, was the original "dilemma".
For all the other controls, just knowing the page name suffices.
Your advice RoyVidar, circumvents this problem, & underscores the redundancy for Perryan77 to acquire the label names, on the tab page!
Appreciate the input, Thank-you!
 
Actually, the problem with the label is that it does not have an Enabled property. A slight modifcation to the code will accomodate the labels, and handle the heirarchy of controls.
Code:
Private Sub cmdCntlList_Click()

   Dim lCtl_ControlID   As Control
   Dim lCtl_InnerCntrl  As Control
   
   For Each lCtl_ControlID In Me.Controls
      If (lCtl_ControlID.Parent.Name = "<pageName>") Then
         If (lCtl_ControlID.ControlType <> acLabel) Then
            lCtl_ControlID.Enabled = False
         End If
      Else
         If (lCtl_ControlID.Parent.Name <> Me.Name) Then
            Set lCtl_InnerCntrl = lCtl_ControlID.Parent
            Do While (lCtl_InnerCntrl.Parent.Name <> Me.Name)
               If (lCtl_InnerCntrl.Parent.Name = "<pageName>") Then
                  If (lCtl_ControlID.ControlType <> acLabel) Then
                     lCtl_ControlID.Enabled = False
                  End If
               End If
               Set lCtl_InnerCntrl = lCtl_InnerCntrl.Parent
            Loop
         End If
      End If
   Next
   
End Sub



Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Glad to help.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
An even more efficient way to do this is to recursively enumerate through only those controls on the desired tab page. It's more efficient because you are only looking at the controls you need to look at, and not all of the controls on the entire form:
Code:
Private Sub cmdCntlList_Click()
   
   Dim lCtl_ControlID   As Control
   
   Set lCtl_ControlID = Me.Controls("pageWell")
   GetAllControls lCtl_ControlID
   
End Sub

Sub GetAllControls(rCtl_ParentCntl As Control)

   Dim lCtl_ChildCntl   As Control
   
   Debug.Print rCtl_ParentCntl.Name
   If (rCtl_ParentCntl.ControlType <> acLabel) Then
      rCtl_ParentCntl.Enabled = Not rCtl_ParentCntl.Enabled
      For Each lCtl_ChildCntl In rCtl_ParentCntl.Controls
         If (lCtl_ChildCntl.Parent.Name = rCtl_ParentCntl.Name) Then
            GetAllControls lCtl_ChildCntl
         End If
      Next
   End If
   
End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Roy & Cajun, Excuse the belated gratitude, I didn't get a chance to check out the FAQ you sent Roy, or Cajun's most recent reply, till now. Between Cajun's suggestions & Roy's follow up, I have dramatically reduced, simplified & made more dynamic, a large part of my previous code, & of course, it has offered me a lot more control for the future.
Stars for both!
 
peryan77 - Haven't heard from you in a while. Were you able to solve the problem? Was anything in the thread helpful? Sure would be nice to know how things turned out. It's always nice to know that your efforts were appreciated.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
I could of sworn I posted a thank you and gave u a star. Wait I did, look above, I said thanks, it works great.

I have not used the second posting of your code. I will try and implement it when I have more time. They have me doing a million and one things all at once.

Thanks again.
 
Sorry, I missed the 'thank you' post.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Hi,

Just following up on this thread as I had a similar issue with only looping through controls on a single page of a tab control...there is just too much waste looping through all controls on all pages of the tab control.

I achieved this by changing

For Each ctl In me.controls
to
For Each ctl In Me.tabName.Pages(4).Controls

Obviously you change tabName to whatever the name of your tab control is, and also set the correct page number in Pages(?)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top