Replies in-line.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Reply to group, rather than allenbrowne at mvps dot org.
mikieb said:
Many thanks for your advice, I will look into this, I'm afraid I'm trying
to
acheive the results I need using macro's as its along time ago that I did
vb
at college.
Is it possible to not run a filter if the reurn is null using a macro?
It is possible with a macro (but probably easier in code.) After your
ApplyFilter (or whatever) action, use the Condition Column to test whether
the form has zero records, e.g.:
[Forms].[Form1].[RecordsetClone].[RecordCount] = 0
and take whatever action you need, such as removing the filter.
Attempting to do this in a macro in Access 2007 may generate a "Sandbox
mode" error.
Of course, this won't prevent the crash, because it still goes through the
case where there are no records.
It may be possible to use DLookup() with the same criteria as the proposed
filter to see if there are any matches, and apply the filter only if there
is at least one matching record. For help with DLookup(), see:
http://allenbrowne.com/casu-07.html
I presume this code achieves this someting similar
Me.Dirty Then Me.Dirty = False
Me.Filter = "(False)"
Me.FilterOn = True
That's just an example. The first line saves any changes: since Access has
to do this before it can apply the filter, I find it helps to be explicit
about it. (It has the effect of processing and clearning a bunch of pending
messages in the queue before attempting to do the next thing.)
A filter string is essentially a WHERE condition from a query. In the end,
it is somehing that evaluates to True (include the record) or False (exclude
the record), for each record. The expression "(False)" doesn't depend on the
data in the record, so it evaluates to False for all records, hence all
records are excluded. (Actually, the WHERE condition could evaluate to Null
too, but that excludes the record.)
The third line just turns the filter on.
It may be of interest to you that I mirrored possibly? the same problem
using the Northwind database, Customer orders form, using filter by form,
querying Company name "xzzx" it returns the message "Acces has stopped
working" and closes.
I doubt that Northwind has a control in the subform for the foreign key, so
you may be able to crash Northwind using the same approach. The AccessField
problem doesn't always occur: I don't have the conditions nailed down
completely, but it tends to be when using a multi-table query as the source
for the subform.
The second part of your reply I work through
If you are still stuck after you work through this, please indicate what
version of Access you are using, and what service pack. (It's on the Help |
About screen.) Also, which Windows you use.