I have created a form that presents the user with a number of drop downs, which pass the user’s selections to a query as parameters.
The problem I have in dealing with null entries. The goal is that when the user leaves a given dropdown blank the query will return ALL data relevant to that field.
At first I thought I could do this simply with a statement like this
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]),,[Forms]![CUSTOM Frm]![MyField])
Where I expected the query would leave the criteria line alone (blank) if the field was Null and use the value stored in it if it was not Null but this statement fails because Access interprets the double commas as a syntax error.
So next I tried explicitly entering a statement between the two commas that would be equivalent to leaving the criteria line blank.
Since placing the statement “Like "*" Or Is Null” in the criteria field returns the desired information (All entries) I expected that I could create a criteria statement something like this.
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]), Like "*" Or Is Null ,[Forms]![CUSTOM Frm]![MyField])
Unfortunately, Access does not accept this as it is “too complex to be evaluated”. It appears to me that the complexity arises because Access refuses to treat the “Like "*" Or Is Null” section as simple text (even if it is enclosed in quotes).
I fail to see what is so complex about
1. Examining the contents a specific field
2. If it is null use a simple OR statement as criteria (or just leave the default criteria unaltered).
3. If it is not null use the contents of the field as criteria.
But that aside, I did find a means of accomplishing what I want on a limited basis by using the following statement which I found on the Web.
[Forms]![CUSTOM Frm]![MyField] Or [Forms]![CUSTOM Frm]![MyField] Is Null
While this works fine for a small number of fields it fails when larger numbers of fields are involved. The reason appears to be that while Access allows the statement to be entered as it appears above, it actually executes it by altering the design of the query. Basically what happens is new fields and rows of criteria are appended to the original query and Access breaks the statement into smaller components utilizing both the original field and the newly created ones to execute it.
When I used this statement as the criteria statement for the 20 fields that I need to work with I ended up with a query that had twenty new fields plus over 100 lines of criteria. Talk about complexity! Needless to say the query bombs.
I know I could work around this by eliminating nulls entries but I really don’t want to go that route.
Does anyone know of a statement that would be functionally equivalent to either
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]), Like "*" Or Is Null ,[Forms]![CUSTOM Frm]![MyField])
Or
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]),,[Forms]![CUSTOM Frm]![MyField])
that Access will accept? Or failing that of a Visual Basic means of accomplishing the same thing? Thanks.
The problem I have in dealing with null entries. The goal is that when the user leaves a given dropdown blank the query will return ALL data relevant to that field.
At first I thought I could do this simply with a statement like this
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]),,[Forms]![CUSTOM Frm]![MyField])
Where I expected the query would leave the criteria line alone (blank) if the field was Null and use the value stored in it if it was not Null but this statement fails because Access interprets the double commas as a syntax error.
So next I tried explicitly entering a statement between the two commas that would be equivalent to leaving the criteria line blank.
Since placing the statement “Like "*" Or Is Null” in the criteria field returns the desired information (All entries) I expected that I could create a criteria statement something like this.
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]), Like "*" Or Is Null ,[Forms]![CUSTOM Frm]![MyField])
Unfortunately, Access does not accept this as it is “too complex to be evaluated”. It appears to me that the complexity arises because Access refuses to treat the “Like "*" Or Is Null” section as simple text (even if it is enclosed in quotes).
I fail to see what is so complex about
1. Examining the contents a specific field
2. If it is null use a simple OR statement as criteria (or just leave the default criteria unaltered).
3. If it is not null use the contents of the field as criteria.
But that aside, I did find a means of accomplishing what I want on a limited basis by using the following statement which I found on the Web.
[Forms]![CUSTOM Frm]![MyField] Or [Forms]![CUSTOM Frm]![MyField] Is Null
While this works fine for a small number of fields it fails when larger numbers of fields are involved. The reason appears to be that while Access allows the statement to be entered as it appears above, it actually executes it by altering the design of the query. Basically what happens is new fields and rows of criteria are appended to the original query and Access breaks the statement into smaller components utilizing both the original field and the newly created ones to execute it.
When I used this statement as the criteria statement for the 20 fields that I need to work with I ended up with a query that had twenty new fields plus over 100 lines of criteria. Talk about complexity! Needless to say the query bombs.
I know I could work around this by eliminating nulls entries but I really don’t want to go that route.
Does anyone know of a statement that would be functionally equivalent to either
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]), Like "*" Or Is Null ,[Forms]![CUSTOM Frm]![MyField])
Or
IIf(IsNull([Forms]![CUSTOM Frm]![MyField]),,[Forms]![CUSTOM Frm]![MyField])
that Access will accept? Or failing that of a Visual Basic means of accomplishing the same thing? Thanks.