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

Show/Hide Group of controls on Switchboard 1

Status
Not open for further replies.

smalty

Technical User
Jan 9, 2005
74
GB
I have a switchboard with 3 'groups' of controls Tagged blue, green, pink.
I would like to have 3 'buttons' each representing a 'group' which when clicked would 'SHOW' the relevant group and hide either of the other two if it were already showing.

I have searched the forum but not found exactly this problem.
Any help greatly appreciated

Smalty
 
something like this but untested
Code:
public sub showHide(strTag as string)
  dim ctrl as access.control
  for each ctrl in me.controls
    if not ctrl.tag = "" then
      ctrl.visible = (ctrl.tag = strTag)
    end if
  next ctrl
end sub
example
Code:
public cmdPink_click()
  showHide("Pink")
end sub
 
Perfect.........thank you.........but why 'Public' not 'Private'. just curious as I am not too familiar with rules on coding.

Smalty
 
How are ya smalty . . .

In the [blue]Tag[/blue] property of each control in each group add the proper word (Blue, Green, Pink) (note: [purple]no quotations please![/purple]).

Expanding on that provided by [blue]MajP[/blue], copy/paste the following to the forms code module:
Code:
[blue]Public Sub showHide(strTag As String)
   Dim ctrl As Access.Control
    
    Me.[purple][B][I]ControlName[/I][/B][/purple].Setfous
    
    For Each ctrl In Me.Controls
      If ctrl.tag = strTag Then
        ctrl.Visible = True
      ElseIf ctrl <> "" Then
        ctrl.Visible = False
      End If
   Next

End Sub[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks also for that Aceman1. But would still like to understand why a 'Public' sub as opposed to a 'Private' one. I am sure I read somewhere that Public isn't/shouldn't be used very often!!!!???? If this is a stupid question I apologise, but I always like to try to understand fully what I learn and not just DO IT without question.

Regards
Smalty
 
No your right. If that is in the form's module then it should have been private and not public.
If private that code can only be called from that form. If public it is visible to the rest of the program. Calling that code from outside the form would not make much sense.
I typed that code quickly in the Tek-tip thread window and thus it was a mistake.
So yes always limit the scope and lifetime of variables, and the scope of procedures.
 
BTW, my code is correct and AceMan's will not work. There is no reason to set the focus to the controls, in fact you cannot do that. You cannot make the control with the focus invisible. You actually often have to do the opposite and set the focus on something else prior to making it invisible. However, you said from a command button and thus the click would ensure the command button has focus.
 
Thank you for the lesson on 'Private' and 'Public'....again I have learnt something valuable from you and this excellent resource (the forum)

As stated earlier your code worked exactly how I wanted it to.

Thanks again
Smalty
 
MajP . . .

Its academic now ... but I did test before I posted and the SetFocus line was for moving the focus to a control not in any group. Its amazing what can be read into a post. I had no Idea you could think for me!

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Sorry AceMan, misinterpreted what you were showing. I was just confused because the OP said it worked perfectly, said that the controls were tagged already, and said that three command buttons were used to show/hide the controls. So I was confused on what in addition you were trying to demonstrate, and why you would move the focus away from the command button that initiated the procedure. But now I understand you were demonstrating a general approach where the control that triggers the show/hide event may be part of the controls that get shown or hidden.
 
MajP . . .

If I had given more detail ... it would've been easily seen on first sight. My Bad!

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top