Update table field

Langels00

Registered User.
Local time
Today, 04:55
Joined
Jan 12, 2014
Messages
11
I have a simple MyAddress Project. It consists of one main table, a couple of queries, some forms and reports. Most fields in the table are typical text fields. The project allows me to select records from the table and print labels for those selected records. One field is a "yes/no" field. If the field value is true, the label prints; otherwise it does not. I have a form which allows me to scan the list of records and mark those I wish to print. So far so good. I am trying to add two buttons to the form to enable me to 1. Clear All and 2. Check All. I am trying to use an UPDATE statement to activate when I click the appropriate button. However, when I execute, I get the error message "Compile error: Sub or Function not defined". I have little experience with Access 10 and suspect the solution is simple, but I can't find it.
The name of the table is tblMyAddresses.
The firld I am trying to UPDATE is PrtLbl.
The update value will be true or false depending on the button clicked.
Since I want to change the values in all records, there is no WHERE required. The code I am trying is as follows:

Option Compare Database
Public Sub CheckAll_Click()
Update tblmyaddresses
Set PrtLbl = False
End Sub

Can anyone help me with this?
 
SQL is not VBA. That is, the code you use to for a query can't just be put into VBA and run, you need to tell VBA that you want it to run SQL. Use the below line of code as the only code in your function:


DoCmd.RunSQL "Update tblmyaddresses Set PrtLbl = False"
 
Thanks plog. I often get confused between VBA and SQL. Your solution did the trick.
 

Users who are viewing this thread

Back
Top Bottom