Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clicking all check boxes programtically

Status
Not open for further replies.

Rajesh99

Programmer
Mar 17, 2003
43
US
I have a table with check box against each row of data. I want to provide a global check box[check all] on top which if clicked should check all check boxes on the form. I do not find any method to that. Any ideas, what method of check box I call? Thanks
 
Try this. I'm on hold with Gateway so can't test it, but it should work.

Code:
    Dim ctl as control

    for each ctl in Me
       if (ctl.controltype = acCheckBox) then ctl = True
    next
 
Actually I have a table of data on form(multi-row). I try below using recordset. Against each row of this tabular form(multi row) I have one check box to identify the row. This code only checks checkbox(print_flag) against row one? I want the code to check all check boxes.

Me.Requery
Set rs = Me.RecordsetClone
If rs.RecordCount > 0 Then
rs.MoveFirst
Do While Not rs.EOF
Me.print_flag = True
rs.MoveNext
Loop
End If
 
How are ya Rajesh99 . . . . .

First, your not seeing the changes via the recordset because your don't [blue]requery the form when the recordset is finished updating[/blue]. Either your current Me.Requery or an additional Me.Requery [blue]should be at the end of code[/blue]. Make it so and it should be fine.

I offer the following as an alternate method. It [blue]toggles[/blue] the checkboxes incase the user accidently hits the button (you substitute names in [purple]purple[/purple]):
Code:
[blue]   Dim SQL As String, Tgl As String
   
   SQL = "UPDATE [purple][b]YourTableName[/b][/purple] SET [print_flag] = "
   
   If Me!print_flag Then
      Tgl = "False;"
   Else
      Tgl = "true;"
   End If
   
   DoCmd.RunSQL SQL & Tgl
   Me.Requery[/blue]


Calvin.gif
See Ya! . . . . . .
 
Hi!

TheAceMan1's method should work, as should yours, with a slight modification, put the/a me.requery at the bottom of the routine too, AND - working with DAO, you need to apply two methods, .Edit and .Update AND assign the value to the recordset field (it needs to be a field in the recordset):

[tt]...
Do While Not rs.EOF
rs.edit
rs!print_flag = True
rs.update
rs.MoveNext
Loop
...[/tt]

Roy-Vidar
 
Aceman,

I'm receiving an error when I try running your toggle code.

runtime error 3144 syntax error in update statement and it is highlighting

DoCmd.RunSQL SQL & Tgl

any ideas?

much appreciated.

tractorvix
 
tractorvix . . . . .

In the [blue]SQL =[/blue] line, make sue you have the right table name and its spelling is correct. Do the same for [blue]print_flag[/blue] If everytthing appears ok, post back the code as you have it.

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top