Trapping no Result

G

Guest

I'm working on a project to search a patient record db. I have the search
form developed and working fine but I'm a bit stuck with the fine tuning
trapping errors. The user selects from two cbo boxes, cbo1 and cbo2, the
results of these two fields builds a string which I use as the WHERE
condition when the frmResults form is opened (DoCmd.Open...). All is great
and even if the two cbo entries don't yield a match the frmResults form opens
with no records. Instead I like to be able to display a Message Box telling
the user that no records match their search criteria and then keep them in
the search form.

Appreciate any help,

Ian.
 
D

Dirk Goldgar

Ian said:
I'm working on a project to search a patient record db. I have the
search form developed and working fine but I'm a bit stuck with the
fine tuning trapping errors. The user selects from two cbo boxes,
cbo1 and cbo2, the results of these two fields builds a string which
I use as the WHERE condition when the frmResults form is opened
(DoCmd.Open...). All is great and even if the two cbo entries don't
yield a match the frmResults form opens with no records. Instead I
like to be able to display a Message Box telling the user that no
records match their search criteria and then keep them in the search
form.

One approach is to put code like this in the results form's Load event:

'----- start of code -----
Private Sub Form_Load()

If Me.Recordset.RecordCount = 0 Then
MsgBox "No records match the search criteria."
DoCmd.Close acForm, Me.Name
End If

End Sub
'----- end of code -----
 

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