Control Visibility Changes by Tag in Code

Prysson

Registered User.
Local time
Today, 21:35
Joined
Sep 23, 2002
Messages
45
Assume I have a form called FRM

The form has a list Box from which the user can select a record.

There is a Next button.

For a number of reasons I want the Next button to change the visibility of the controls so that the first list box is "hidden" with its selected value and a second control is made "visible" with a number of options determined by the selection in the first list box.


How do I code this into the "Next" command button to change the "visible" property of the controls and refresh the form?
 
You can loop throught the controls collection of the form

Code:
Dim ctr as Control

For Each ctr in FRM.Controls
  'check you criteria and set control's visible property
Next ctr

FRM.Refresh
 
I am a little shaky on what I need to add to the code for this

Here is the code I have


Private Sub cmd1_Click()

Dim ctrl As Control

Me.cmd4.SetFocus
For Each ctrl In Me.Controls
If (ctlr.Tag) = "Loc1" Then
ctrl.Visible = False
End If
If (ctlr.Tag) = "Loc2" Then
ctrl.Visible = True
End If

Next ctrl

Me.Refresh


End Sub

You can see that what I am trying to do is test whether the Tag Property is a certain value then change the Visible Property value...BUt I am not at all certain about the correct code for The If/Then statement.
 
If cmd1 is only to make all controls with a tag of "Loc1" Visible to false and all controls with a tag of "Loc2" Visible to true then use this. This will leave all controls that do not have a tag of "Loc1" or "Loc2".

Code:
Private Sub cmd1_Click() 

Dim ctrl As Control 

  Me.cmd4.SetFocus 
  For Each ctrl In Me.Controls 
    If (ctlr.Tag) = "Loc1" Then 
      ctrl.Visible = False 
    ElseIf (ctlr.Tag) = "Loc2" Then 
      ctrl.Visible = True 
    End If 
  Next ctrl 

Me.Refresh 

End Sub
 

Users who are viewing this thread

Back
Top Bottom