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 / November 2006

Tip: Looking for answers? Try searching our database.

Checking all boxes on a form.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James O - 13 Nov 2006 18:51 GMT
Hello all,

I have a form that connect to a query, so the data on the from changes
depending on what is selected in the query. Each record has a check box. I
have a select all button on my form and when somone clicks it I want all the
boxes checked. This is the crrent code Im using.

Private Sub Command75_Click()
Dim ctl As Control
   On Error Resume Next
   For Each ctl In Me.Controls
      If ctl.ControlType = acCheckBox Then ctl.Value = True
   Next ctl
End Sub

The problem is that it is only checking the first box and then stopping.
Thanks for any advice you can offer!

James O
BruceM - 13 Nov 2006 19:25 GMT
I think you just need to add End If before Next ctl.

> Hello all,
>
[quoted text clipped - 16 lines]
>
> James O
James O - 13 Nov 2006 19:37 GMT
Thanks for the reply BruceM

Ok I changed to:

Dim ctl As Control
   On Error Resume Next
   For Each ctl In Me.Controls
      If ctl.ControlType = acCheckBox Then
      ctl.Value = True
      End If
   Next ctl

I unfortunately still get the same problem... it checks the first box and
then stops.

> I think you just need to add End If before Next ctl.
>
[quoted text clipped - 18 lines]
> >
> > James O
Marshall Barton - 13 Nov 2006 19:32 GMT
> I have a form that connect to a query, so the data on the from changes
>depending on what is selected in the query. Each record has a check box. I
[quoted text clipped - 10 lines]
>
>The problem is that it is only checking the first box and then stopping.

There should be no reason to loop through all the controls
just to locate a single check box.  Just use the name of the
check box:
    Me.thecheckbox = True

If you can get hold of the criteria used to select the
form's records, you should construct an Update query to
modify all the records in one operation:
strSQL = "UPDATE thetable SET theyesnofield = True " _
                & "WHERE " & somethingorother
CurrentDb.Execute strSQL

If that's out of the question, then you can loop through the
form's records and set the field's (not the control's)
value:

With Me.RecordsetClone
    If .RecordCount > 0 Then
        .MoveFirst
        Do Until .EOF
            .Edit
                !theyesnofield = True
            .Update
            .MoveNext
        Loop
    End If
End With

Signature

Marsh
MVP [MS Access]

James O - 13 Nov 2006 19:45 GMT
Thanks Marshall!

I went with your 3rd option which worked like a charm. Perfect I appreciate
the help very much.

> > I have a form that connect to a query, so the data on the from changes
> >depending on what is selected in the query. Each record has a check box. I
[quoted text clipped - 38 lines]
>     End If
> End With
 
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.