
Signature
with thanks Mikie
"mike" wrote:
Hi Allen
you gave me afew ideas and I did try
Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)
If Me.Filter = "(false)" Then Me.FilterOn = False Else Me.FilterOn = True
End Sub
the query the form is based has numerical and text fields this produced
variable results on filtering, some times it worked other times it crashed
(possibly worse when queried on text fields"), I suspect there is, as you say
another underlying problem, unless my code is nonsense?
will work through the rest of your reply in the next few days
again thanks Mike
"mike" wrote:
> Hi Allen
>
[quoted text clipped - 36 lines]
> >
> > any adivce would be great
Replies in-line.

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Many thanks for your advice, I will look into this, I'm afraid I'm trying
> to
[quoted text clipped - 3 lines]
>
> 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.
> again, many thanks for your time
>
[quoted text clipped - 16 lines]
>>
>> any adivce would be great
mikieb - 15 Dec 2007 22:26 GMT
Hi Allen
I have been working through this for a few hours and have tried not using
"name autocorrect" which is now unchecked. Did not hold much hope that my
simple code attempts would solve this, as the crash seems to be variable.
In the end working at the solution from the ground up seems to have done the
trick.
I started by creating a new simpilfied main form with a basic sub form
(Access 2003 using vista)
tried filter by form and data that would return zero result and it worked.
next I tried importing my sub forms and it still worked fine and even added
a bit more complication by linking a query to the main form and still no
crash, well its late and I'm sure it will probably crash in the moring but I
seem to have a solution.
I did try trouble shootiing the problem in this way the other day, but kept
my main form when rebuilding.
it would take a day or so to sort out the forms which are causing problems
so will work through it.
This database has slowly evolved over some years, I think possibly through 3
versions of Access and several verions of windows, perhaps like me it needs a
rethink.
your advice has been very helpful, will look further in to improving my use
of vb.

Signature
thanks Mike
> Replies in-line.
>
[quoted text clipped - 80 lines]
> >>
> >> any adivce would be great
Allen Browne - 16 Dec 2007 02:32 GMT
Good news.

Signature
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
> Hi Allen
>
[quoted text clipped - 32 lines]
> use
> of vb.