Command Button to Check All Checkboxes (1 Viewer)

Paladon

Registered User.
Local time
Yesterday, 20:12
Joined
Jul 11, 2006
Messages
10
Hi Everyone

I am building a database for a friend of mine and I would like to give the user the option to mark all of the checkboxes simultaneously. The Checkbox field is called "[Printed Yes/No]". I have set up the command button which is called Check All and I would like it to function like a light switch enabling and disabling all the checkboxes when disired. I am unsure how to make this happen, I would imagine that it will require vb code which I am only just begining to learn.

Thanks for any help. :)

I have attached a screen shot of the Form in question.
Please Ignore the entered data it is random test data.
 

Attachments

  • ServiceDateUAImage.JPG
    ServiceDateUAImage.JPG
    60.3 KB · Views: 611

whitesmoke

Registered User.
Local time
Yesterday, 20:12
Joined
Jun 23, 2006
Messages
29
yes it will take vb code to do it. you can either create another 2 checkbox ( or option box) or create 2 buttons one for all and one for none..
create an expression event (code) for on_click

use field1.value = -1
field2.value = -1

so on so forth
of uncheck its field.value = 0
 

ejstefl

Registered User.
Local time
Today, 04:12
Joined
Jan 28, 2002
Messages
378
You could do it with an update query. You can use the same criteria that you use for the form's recordset, and have it update the checkbox to either yes or no.
 

Paladon

Registered User.
Local time
Yesterday, 20:12
Joined
Jul 11, 2006
Messages
10
Thanks for your advice I will give both options a go

Thanks
 

stepdown

Registered User.
Local time
Today, 04:12
Joined
Jul 4, 2006
Messages
16
Hi, I've tried a similar bit of code on mine, but I can only change the value that I have selected, so the button changes the current checkbox, but doesn't change all the checkboxes on that page. Is there a way to make it change all of the items on the form?

Picture added in case I am not making sense.
http://img96.imageshack.us/img96/9730/exampleqq0.jpg
 

ejstefl

Registered User.
Local time
Today, 04:12
Joined
Jan 28, 2002
Messages
378
Yes, like I posted earlier, the easiest way is to use an update query. Just run the query when the user clicks on the "check all" button.

Whitesmoke's method above will only modify the current record.
 

stepdown

Registered User.
Local time
Today, 04:12
Joined
Jul 4, 2006
Messages
16
Ahah, I was hoping to modify it further so that it would be a single tickbox rather than two buttons, but I guess two update queries would work as well.

Thanks :)
 

Paladon

Registered User.
Local time
Yesterday, 20:12
Joined
Jul 11, 2006
Messages
10
I followed the update query soultion as posted by ejstefl which works perfectly.

Thanks :)
 

ejstefl

Registered User.
Local time
Today, 04:12
Joined
Jan 28, 2002
Messages
378
stepdown said:
Ahah, I was hoping to modify it further so that it would be a single tickbox rather than two buttons, but I guess two update queries would work as well.

Thanks :)

Well, the problem with your code is that when you run it, you only have access to the currently selected record. In order to get to all the records, you need to do either an update query, or open the form's recordset.
 

ansentry

Access amateur
Local time
Today, 13:12
Joined
Jun 1, 2003
Messages
995
Put a toggle button on your form, name it tglYesNo

Paste the code into your form, change the "names" to suit.

txtRequired is the name of the check box on your form, (change to suit)

tblData is the name of the table. (change to suit)

Required is the name of the check box field in the table. (change to suit)

Code:
Private Sub Form_Load()
    If Me.[COLOR="RoyalBlue"]txtRequired[/COLOR].Value = True Then
        Me.tglYesNo.Caption = "Un-Tick All"
        Me.tglYesNo.Value = True
  
    ElseIf Me.[COLOR="RoyalBlue"]txtRequired[/COLOR].Value = False Then
        Me.tglYesNo.Caption = "Tick All"
        Me.tglYesNo.Value = False
        End If
End Sub

Private Sub tglYesNo_Click()
    Select Case tglYesNo

        Case True

          DoCmd.SetWarnings False
            DoCmd.RunSQL "UPDATE [COLOR="Blue"]tblData [/COLOR]SET [COLOR="RoyalBlue"]tblData[/COLOR].[COLOR="RoyalBlue"]Required[/COLOR] = On"
            DoCmd.SetWarnings True
            Me.Requery
            Me.tglYesNo.Caption = "Un-Tick All"
    
        Case False
            DoCmd.SetWarnings False
            DoCmd.RunSQL "UPDATE [COLOR="Blue"]tblData[/COLOR] SET [COLOR="RoyalBlue"]tblData.Required[/COLOR] = Off"
            DoCmd.SetWarnings True
            Me.Requery
            Me.tglYesNo.Caption = "Tick All"
    End Select

End Sub


I hope this works for you.
 

stepdown

Registered User.
Local time
Today, 04:12
Joined
Jul 4, 2006
Messages
16
ansentry said:
I hope this works for you.

Thanks for the great code, for the moment I have implemented the control buttons with "Select All" and "Deselect All" on for the moment, but if the users want to change it to a toggle or checkbox that code will be invaluable.

Thanks everybody. I feel like I'm getting good at this ;)
 

Users who are viewing this thread

Top Bottom