Form goes blank on filtering

T

Tony G

Hello World,

Problem: I have a simple form based on a three table query
that works well except when a filter is applied (via right-
click, filter for and entering say, London for a county
field) that results in zero records being returned.

When this happens the form goes totally blank and although
it does not hang it only returns to normal when the filter
is removed.

Question: Is it possible to trap this event and remove the
filter automatically should zero records be returned in
order to avoid freaking-out the user. I tried obvious
things like OnApplyFilter but these events seem to occur
before the query updates.

Any help would be appreciated.
 
V

Van T. Dinh

Check Access VB Help on the ApplyFilter Event of the Form. I think you can
use DCount or Recordset to check whether the criteria will return any record
or not and if no records, you can cancel the ApplyFilter Event.
 
T

Tony G

Thanks Van, you are the man.
Here's what I did for anyone with the same problem:

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType
As Integer)
Dim z As Integer
z = DCount("[ContactID]", "CampaignsQuery", Me.Filter)
If z < 1 Then
MsgBox "cancel message here" vbInformation
Cancel = True
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top