简体   繁体   中英

MS Access SQL Query statement

This statement needs to get a list of emails for some friends to volunteer. I need the WHERE clause to return from the list of checkboxes only those volunteers with an email also. The following code only works when the IsVolunteer checkbox is checked and the Has an Email is checked. What is wrong with the SQL statement?

So the result should be like... Bill Turner... bturner@gmail.com... and show those checked volunteer items to requery in the form. Only those who have emails should be in this view.

If Abs(Me.hasEmailCkb.Value) = 1 And Abs(Me.CheckIsVol.Value) = 1 Then
VolToEMail = "Select * from [Members] where ([Food] = true Or [Setup] = true Or [Carpool] = true Or [Mail] = true AND [Email] <> NULL) Order By [LName] ASC"
Me.Members_subform.Form.RecordSource = VolToEMail

Thank you for helping!

You need parentheses before the AND :

Select *
from [Members]
where ([Food] = true Or [Setup] = true Or [Carpool] = true Or [Mail] = true) AND 
      ([Email] IS NOT NULL)
Order By [LName] ASC;

Note that <> NULL should be IS NOT NULL . <> NULL will always return NULL , which is treated as false.

AND [Email] <> NULL

This does not work. You need to use:

AND [Email] IS NOT NULL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM