问题
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