Can I group controls together and apply code to the group

  • Thread starter Thread starter Julia B
  • Start date Start date
J

Julia B

Hi

I've got a form with lots of entry fields. When I open the form I want them
to be invisible but then, under certain circumstances want to make them
visible again. They may go back to being invisible later.

I was wondering if there was any way to change a property to a group of
controls in one go? Can I group them and do the following:

If scenario1 then
group.visible = true
else
group.visible = false
end if

I hope so, otherwise it's going to take ages to write the code!!

Thanks in advance
Julia
 
Hi

I've got a form with lots of entry fields. When I open the form I want them
to be invisible but then, under certain circumstances want to make them
visible again. They may go back to being invisible later.

I was wondering if there was any way to change a property to a group of
controls in one go? Can I group them and do the following:

If scenario1 then
group.visible = true
else
group.visible = false
end if

I hope so, otherwise it's going to take ages to write the code!!

Thanks in advance
Julia

First, manually enter some text in each control's Tag property to
identify which group you wish that control to be part of, something
like "GroupA" or "GroupB".

Then use code to make just that one group of controls visible or not:

Dim ctl as Control
If [SomeControl] = Scenario1 Then
For each ctl in Me.Controls
if ctl.tag = "GroupA" then
ctl.Visible = True
ElseIf ctl.Tag = "" Then
ctl.Visible = True
Else
ctl.Visible = False
End IF
Next
Else
For each ctl in Me.Controls
if ctl.tag = "GroupB" then
ctl.Visible = true
ElseIf ctl.Tag = "" Then
ctl.Visible = True
Else
ctl.Visible = False
End IF
Next
End If

Only controls whose Tag property is GroupA or GroupB will be effected.
 
There are no control arrays in Access, but you can loop through the
controls collection and do things. Also there is a Tag property in every
control, so you could loop through all the controls and check the tag
property, if, for instance you wanted to exempt some of your controls:

Add this to a standard module:

Public Sub HideIt(frm As Form)
On Error Resume Next
Dim ctl As Control
For Each ctl In frm.Controls
With ctl
If ctl.Tag = 1 Then
ctl.Visible = False
End If
End With
Next ctl
Set ctl = Nothing
Set frm = Nothing
End Sub

Then in your form, you can do:

If scenario1 Then
HideIt
End If
 
That's excellent, thanks very much!!
Julia

fredg said:
Hi

I've got a form with lots of entry fields. When I open the form I want them
to be invisible but then, under certain circumstances want to make them
visible again. They may go back to being invisible later.

I was wondering if there was any way to change a property to a group of
controls in one go? Can I group them and do the following:

If scenario1 then
group.visible = true
else
group.visible = false
end if

I hope so, otherwise it's going to take ages to write the code!!

Thanks in advance
Julia

First, manually enter some text in each control's Tag property to
identify which group you wish that control to be part of, something
like "GroupA" or "GroupB".

Then use code to make just that one group of controls visible or not:

Dim ctl as Control
If [SomeControl] = Scenario1 Then
For each ctl in Me.Controls
if ctl.tag = "GroupA" then
ctl.Visible = True
ElseIf ctl.Tag = "" Then
ctl.Visible = True
Else
ctl.Visible = False
End IF
Next
Else
For each ctl in Me.Controls
if ctl.tag = "GroupB" then
ctl.Visible = true
ElseIf ctl.Tag = "" Then
ctl.Visible = True
Else
ctl.Visible = False
End IF
Next
End If

Only controls whose Tag property is GroupA or GroupB will be effected.
 
Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
Jan Baird is out of the country until September 20. Every effort will be
made to respond to messages, but please be patient.
 
Back
Top