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 / July 2007

Tip: Looking for answers? Try searching our database.

Looping through Ctls on a Form, then referring to it by "name"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Access101 - 24 Jul 2007 00:58 GMT
I would like to be able to click a button on a form, and make all the
controls that are check boxes TRUE (without having to know their names before
the code runs: that is, I know how to do Me.Chk1.value = true)

There's a line in the code below (written as pseudo code so you can
hopefully understand what I'm asking) that obviously doesn't work:

 If the Control is a check box Then
      Me.ctl.Properties ("Name").value = True

Any help is appreciated.

Private Sub cmdListProperties_Click()
   ListControlProps Me
End Sub

Public Sub ListControlProps(ByRef frm As Form)
   Dim ctl As Control
   Dim prp As Property

   On Error GoTo props_err

   For Each ctl In frm.Controls
       For Each prp In ctl.Properties
           If the Control is a check box Then
               Me.ctl.Properties ("Name").value = True
           End If
       Next prp
   Next ctl
Allen Browne - 24 Jul 2007 02:33 GMT
This should do it:

   For Each ctl In frm.Controls
       If ctl.ControlType = acCheckBox Then
           ctl = True
       End If
   Next ctl

If you have heaps of *bound* check boxes on a form, it may indicate the
table is not well designed. See:
   Don't use Yes/No fields to store preferences
at:
   http://allenbrowne.com/casu-23.html

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

>I would like to be able to click a button on a form, and make all the
> controls that are check boxes TRUE (without having to know their names
[quoted text clipped - 26 lines]
>        Next prp
>    Next ctl
Access101 - 24 Jul 2007 17:16 GMT
Allen,

Very helpful all around - thanks for the Yes/No article too, I'll be passing
that on.

Thanks a lot

> This should do it:
>
[quoted text clipped - 40 lines]
> >        Next prp
> >    Next ctl
 
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.