Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2008

Tip: Looking for answers? Try searching our database.

Can I group controls together and apply code to the group

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Julia B - 22 May 2008 15:23 GMT
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
fredg - 22 May 2008 15:55 GMT
> Hi
>
[quoted text clipped - 15 lines]
> 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.
   
Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Julia B - 22 May 2008 16:01 GMT
That's excellent, thanks very much!!
Julia

> > Hi
> >
[quoted text clipped - 47 lines]
> Only controls whose Tag property is GroupA or GroupB will be effected.
>    
Jan Baird - 27 May 2008 20:50 GMT
Jan Baird is out of the country until September 20.   Every effort will be
made to respond to messages, but please be patient.
Arvin Meyer [MVP] - 22 May 2008 15:59 GMT
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
Signature

Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

> Hi
>
[quoted text clipped - 16 lines]
> Thanks in advance
> Julia
Jan Baird - 27 May 2008 20:50 GMT
Jan Baird is out of the country until September 20.   Every effort will be
made to respond to messages, but please be patient.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.