No Data results in blank screen

E

Ernie

I have a main form acting the part of a switchboard. On
this you choose from a variety of selection criteria. This
criteria is then used in a query which displays a new form
with it's own subform.

In general the query should be able to return between 1
and 1000 records for display. Occasionally, however there
is no records returned by the query.

When this happens, the second form displays a blank screen
with no fields and no data. Even the command buttons for
this form are gone.

What I need to do is on got focus for this form, I need to
check to see if there is data to display and if not, show
a message box to that effect. Or perhaps this should be on
the on lost focus for the main form.

I've tried placing:

If Me.CboARSearch.ARNumber = Null Then
MsgBox "no data to display"
End If

in the On Got Focus event for the second form (as well as
in the On Lost Focus even on the main form) with no effect
whatsoever.

CboARSearch is a combo box on the secondary form with its
record source as the query mentioned above. It works when
there is date but ...

How can I get a message box stating that there is no data
and avoid displaying a completely blank screen?

Thank you in advance,
 
N

Nikos Yannacopoulos

Ernie,

Put the folowing code in the second form's On Open (or On Load) event:

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No records found"
DoCmd.Close acForm, Me.Name
End If

HTH,
Nikos
 

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