Check box question

  • Thread starter Thread starter PostWise
  • Start date Start date
P

PostWise

I have a form with a check box on it. The box determines whether or
not that record will be printed. I would like to add a check box that
will allow me to select or deselect all the check boxes on all records.
Similar to the way many web mail applications work. Any guidance
would be appreciated.
 
PostWise said:
I have a form with a check box on it. The box determines whether or
not that record will be printed. I would like to add a check box that
will allow me to select or deselect all the check boxes on all
records. Similar to the way many web mail applications work. Any
guidance would be appreciated.

Assuming the current check box is bound to a boolean (yes/no) field in
the form's recordsource,
most likely you'd put the "select all" check box in the form's header
section, and use its AfterUpdate event to execute an update query that
modifies the boolean field for all records. The relevant line of code
might look something like this:

CurrentDb.Execute _
"UPDATE [TableOrQueryName] SET [SelectField] = True", _
dbFailOnError
 
Thanks for the guidance, I am new to the programming part of access.

Yes, the check box is bound to a boolean (yes/no) field in the forms
record source.

I know how to create an update query, but I haven't a clue how to
insert that code so that when the query runs it changes the Yes/No
field to either true or false.

Sorry if my rookie question is not appropriate for this forum, but any
additional info you could provide this newbie would be appreciated.

jim
 
Thanks for the guidance, I am new to the programming part of access.

Yes, the check box is bound to a boolean (yes/no) field in the forms
record source.

I know how to create an update query, but I haven't a clue how to
insert that code so that when the query runs it changes the Yes/No
field to either true or false.

Sorry if my rookie question is not appropriate for this forum, but any
additional info you could provide this newbie would be appreciated.

jim

This check box would b placed in the Form Header or Footer section.
Place the codein in it's AfterUpdate event.

1) Display this check box property sheet.

2) Click on the Event tab.
On the On Click line write
[Event Procedure]

3) Click on the little button with 3 dots that appears on that line.

4) When the code window opens, the cursor will be flashing between 2
already existing lines of code. Between those 2 lines, write:

CurrentDb.Execute "UPDATE [TableOrQueryName] SET [SelectField] = Not
[SelectField]", dbFailOnError

The above should be all on one line.

5) Exit the code window and save the changes.

It will toggle the check box attached to each record to True or False.
Change [TableOrQueryName] to the actual name of the table or Query.
Change [SelectField] to the actual name of the check box field.
 
Hello Fred:

Haven't had a chance to get back to work on this until today. Here is
my code:

Private Sub Check33_AfterUpdate()

End Sub

Private Sub Check33_Click()
CurrentDb.Execute "UPDATE [qryDelivery] SET [Print] = Not [Print],
dbFailOnError"



End Sub


When I click on the checkbox in the header I get:

Runtime error '3144:'

Syntax error in update statement.

When I click on individual records in toggles the checkbox in the
header however.

Any thoughts?

jim
 
Hello Fred:

Haven't had a chance to get back to work on this until today. Here is
my code:

Private Sub Check33_AfterUpdate()

End Sub

Private Sub Check33_Click()
CurrentDb.Execute "UPDATE [qryDelivery] SET [Print] = Not [Print],
dbFailOnError"

End Sub

When I click on the checkbox in the header I get:

Runtime error '3144:'

Syntax error in update statement.

When I click on individual records in toggles the checkbox in the
header however.

Any thoughts?

jim
** The CheckBox (Check33) should NOT be bound to any field.
In other words, it's control source should be blank.

** The [Print] check box field should be a Yes/No field in your TABLE.

** Place the code in the CheckBox AfterUpdate event.

My code should toggle all of the [Print] check boxes. If the check box
in a record is true it becomes false. If it was false it becomes true.
Is that what you want?
Or did you want to turn all of them False? or True?

To toggle those that are True to False, and those that are False to
True:
CurrentDb.Execute "UPDATE [YourTableName] SET [YourTableName].[Print]
= Not [Print], dbFailOnError"

To set all [Print] checkboxes to False:
CurrentDb.Execute "UPDATE [YourTableName] SET [YourTableName].[Print]
= 0, dbFailOnError"

To set all [Print] CheckBoxes to True:
CurrentDb.Execute "UPDATE [YourTableName] SET [YourTableName].[Print]
= -1, dbFailOnError"
 
Hello Fred:

Haven't had a chance to get back to work on this until today. Here is
my code:

Private Sub Check33_AfterUpdate()

End Sub

Private Sub Check33_Click()
CurrentDb.Execute "UPDATE [qryDelivery] SET [Print] = Not [Print],
dbFailOnError"

End Sub

When I click on the checkbox in the header I get:

Runtime error '3144:'

Syntax error in update statement.

When I click on individual records in toggles the checkbox in the
header however.

Any thoughts?

jim
** The CheckBox (Check33) should NOT be bound to any field.
In other words, it's control source should be blank.

** The [Print] check box field should be a Yes/No field in your TABLE.

** Place the code in the CheckBox AfterUpdate event.

My code should toggle all of the [Print] check boxes. If the check box
in a record is true it becomes false. If it was false it becomes true.
Is that what you want?
Or did you want to turn all of them False? or True?

To toggle those that are True to False, and those that are False to
True:
CurrentDb.Execute "UPDATE [YourTableName] SET [YourTableName].[Print]
= Not [Print], dbFailOnError"

To set all [Print] checkboxes to False:
CurrentDb.Execute "UPDATE [YourTableName] SET [YourTableName].[Print]
= 0, dbFailOnError"

To set all [Print] CheckBoxes to True:
CurrentDb.Execute "UPDATE [YourTableName] SET [YourTableName].[Print]
= -1, dbFailOnError"

Whoops!!!
As soon as I clicked send I caught another problem.
Your quotes are in the wrong position, and as I copied your
expression, so were my quotes.

Move the last quote on all of the above Execute statements to just
before the comma, i.e.
CurrentDb.Execute "UPDATE [YourTableName] SET [YourTableName].[Print]
= Not [Print]", dbFailOnError
 
Back
Top