Command Button to Check Checkbox

Y

yons

Trying to create a command button to check certain boxes.
Table is Addresses
Married is checkbox
PrintLabel is checkbox

Want to check printlabel on all forms that married is not checked.
The If statement works on the form I am on only,
so I tried an SQL but says syntax error.


Private Sub cmdCheckAllPrintLabel_Click()
On Error GoTo Err_cmdCheckAllPrintLabel_Click
'If Me.Married = False Then
'Me.[Print Label] = True
'End If
CurrentDb.Execute "UPDATE Addresses Where [Married] = 0 Set [Print Label] =
-1", dbFailOnError
Me.Requery

Exit_cmdCheckAllPrintLabel_Click:
Exit Sub

Err_cmdCheckAllPrintLabel_Click:
MsgBox Err.Description
Resume Exit_cmdCheckAllPrintLabel_Click

End Sub

Thanks in advance.
 
F

fredg

Trying to create a command button to check certain boxes.
Table is Addresses
Married is checkbox
PrintLabel is checkbox

Want to check printlabel on all forms that married is not checked.
The If statement works on the form I am on only,
so I tried an SQL but says syntax error.

Private Sub cmdCheckAllPrintLabel_Click()
On Error GoTo Err_cmdCheckAllPrintLabel_Click
'If Me.Married = False Then
'Me.[Print Label] = True
'End If
CurrentDb.Execute "UPDATE Addresses Where [Married] = 0 Set [Print Label] =
-1", dbFailOnError
Me.Requery

Exit_cmdCheckAllPrintLabel_Click:
Exit Sub

Err_cmdCheckAllPrintLabel_Click:
MsgBox Err.Description
Resume Exit_cmdCheckAllPrintLabel_Click

End Sub

Thanks in advance.


regarding: >Want to check printlabel on all forms that married is not
checked.<
It seems you are mixing up the word 'forms' for the word 'records'.
A table contains records (which in turn contains fields) which stores
the data.
A form displays the record's data and allows data entry and
manipulation.

Try it this way:

CurrentDb.Execute "UPDATE Addresses Set Addresses.[Print Label] =
-1 Where [Married] = 0;", dbFailOnError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Command Button to Check Checkbox 5
Command Button Not Executing 24
Requery subform doesn't display all records 1
Command Button 1
lock button 15
If a record doesn't exist 12
Help with code 3
New Record 8

Top