MS Access query check if form field is empty

假如想象 提交于 2019-12-24 09:59:51

问题


I have a multi-field form and use it to retrieve records of a table. If there is no user input in a field I want to allow "*" and Null Values for the according column, the user input otherwise.

I tried

Like IIf([Forms]![frm_searchForm]![Titel]="" Or IsNull([Forms]![frm_searchForm]![Titel]);Like "*" Or Is Null;[Forms]![frm_searchForm]![Titel])

as well as

Like IIf(IsEmpty([Forms]![frm_searchForm]![Titel]);Like "*" Or Is Null;[Forms]![frm_searchForm]![Titel])

But in both cases, the IIf function always triggers the else expression. How can I check whether the field in the form is empty? Is this even possible without VB?

Thanks


回答1:


AFAICT, when [Forms]![frm_searchForm]![Titel] contains a value, you want only those rows where some field contains that value.

But, if [Forms]![frm_searchForm]![Titel] is Null or an empty string, you want to retrieve all the rows.

If that is correct, try a WHERE clause similar to this:

WHERE
       Len([Forms]![frm_searchForm]![Titel] & '') = 0
    OR some_field Like '*' & [Forms]![frm_searchForm]![Titel] & '*'

Also add a PARAMETERS clause at the beginning of your SQL statement:

PARAMETERS [Forms]![frm_searchForm]![Titel] Text ( 255 );


来源:https://stackoverflow.com/questions/12820453/ms-access-query-check-if-form-field-is-empty

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