I have a continuous form in Access 2007 called “Leadership Contact List.” It has a checkbox control for each record (bound to a field in the underlying table) that is used to email or create mailing labels for the selected contacts. In the form header, there is a “Select All” checkbox control which (of course) selects all the checkboxes. The form also has a combo box in the header that filters the records according to “agency type.”
What I want is to create labels or email only selected contacts within the filtered set, with the option to select them all at once using the "Select All" control.
The “Select All” works great, until the form is filtered. The code behind “Select All” continues to set all the checkboxes as true, even if they aren’t showing in the form. So when the “Email Selected Contacts” or “Create Mailing Labels for Selected Contacts” buttons are clicked, the results are not filtered at all.
I have tried to add additional criteria to the Where clause in the SQL statement of the On Click event to account for the filter, but I get the error “Too few parameters. Expected 1” (error #3061). I don’t know if it’s because I have the syntax wrong or because I’m trying to do something I can’t.
Here’s the code that works:
Here's the code that errors out:
Any help (or alternative suggestions) would be greatly appreciated!
Thanks in advance.
What I want is to create labels or email only selected contacts within the filtered set, with the option to select them all at once using the "Select All" control.
The “Select All” works great, until the form is filtered. The code behind “Select All” continues to set all the checkboxes as true, even if they aren’t showing in the form. So when the “Email Selected Contacts” or “Create Mailing Labels for Selected Contacts” buttons are clicked, the results are not filtered at all.
I have tried to add additional criteria to the Where clause in the SQL statement of the On Click event to account for the filter, but I get the error “Too few parameters. Expected 1” (error #3061). I don’t know if it’s because I have the syntax wrong or because I’m trying to do something I can’t.
Here’s the code that works:
Code:
If Me.SelectAll = True Then strSQL = "Update [Secondary ManualContacts Table] SET [Secondary ManualContacts Table].[Send Email] = True" strSQL = strSQL & " WHERE [Secondary ManualContacts Table].[Send Email] = False" & ";" CurrentDb.Execute strSQL, dbFailOnError Me.Refresh ElseIf Me.SelectAll = False Then strSQL = "Update [Secondary ManualContacts Table] SET [Secondary ManualContacts Table].[Send Email] = False" strSQL = strSQL & " WHERE [Secondary ManualContacts Table].[Send Email] = True" & ";" CurrentDb.Execute strSQL, dbFailOnError Me.Refresh End If
Here's the code that errors out:
Code:
If Me.SelectAll = True Then strSQL = "Update [Secondary ManualContacts Table] SET [Secondary ManualContacts Table].[Send Email] = True" strSQL = strSQL & " WHERE (([Secondary ManualContacts Table].[Send Email] = False) AND ([ManualContacts Table].[Agency Type] ='" & Forms![LeadershipEmailListALL].[cbofltrAgencyType] & "'))" CurrentDb.Execute strSQL, dbFailOnError Me.Refresh ElseIf Me.SelectAll = False Then strSQL = "Update [Secondary ManualContacts Table] SET [Secondary ManualContacts Table].[Send Email] = False" strSQL = strSQL & " WHERE (([Secondary ManualContacts Table].[Send Email] = True) AND ([ManualContacts Table].[Agency Type]='" & Forms![LeadershipEmailListALL].[cbofltrAgencyType] & "'))" CurrentDb.Execute strSQL, dbFailOnError Me.Refresh End If
Thanks in advance.
Comment