Access 2007-Search Form does not return all values because of a blank field--Can't seem to find the LIKE that matches

帅比萌擦擦* 提交于 2020-01-04 14:16:12

问题


First of all thank you for your time and sorry if some issues are unclear, this is my first message here.

I'm having a problem with a custom search form I have made on ACCESS 2007.

Here is my database:

Here is my search form:

The main issue I have is that whenever I enter values in firstname, lastername, address, etc. It works totally fine.

But as soon as I get to work phone, mobile or email, it doesn't show me "Florence Fluflo" because her fields are blank for these categories.

Now I have tried in the "Criteria" of the field Work phone to put these:

  • LIKE ""
  • LIKE "*" & [Forms]![frm_search]![WorkPhone1] & "*" OR "IsNull"
  • =" " OR =""
  • LIKE " "
  • LIKE "*"

Nothing works... and it's pretty weird because I have done SQL and the SQL statement looks perfectly fine:

SELECT CLIENTS.First_name, 
       CLIENTS.Surname, 
       CLIENTS.Address, 
       CLIENTS.Suburb, 
       CLIENTS.Postcode, 
       CLIENTS.Home_phone, 
       CLIENTS.Work_phone
FROM CLIENTS
WHERE (((CLIENTS.First_name) Like "*" & [Forms]![frm_search]![Firstname1] & "*") 
    AND ((CLIENTS.Surname) Like "*" & [Forms]![frm_search]![LastName1] & "*") 
    AND ((CLIENTS.Address) Like "*" & [Forms]![frm_search]![Address1] & "*") 
    AND ((CLIENTS.Suburb) Like "*" & [Forms]![frm_search]![Suburb1] & "*") 
    AND ((CLIENTS.Postcode) Like "*" & [Forms]![frm_search]![Postcode1] & "*") 
    AND ((CLIENTS.Home_phone) Like "*" & [Forms]![frm_search]![HomePhone1] & "*") 
    AND **((CLIENTS.Work_phone) Like "*" & [Forms]![frm_search]![WorkPhone1] & "*" OR (CLIENTS.Work_phone) Like ""))**;

回答1:


If you write "IsNull" (in quotes), it will be considered as a string. So, the proper way to verify if a field is null would be like this IS NULL That means all you need to do for your thing to work is to write

OR IS NULL

after your LIKE statement



来源:https://stackoverflow.com/questions/9814016/access-2007-search-form-does-not-return-all-values-because-of-a-blank-field-can

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!