Error trapping null query results

G

Guest

Greetings,

I am working on an employee database and have a query that searches
predefined job classifications for matches with employee qualifications.
Sometimes no match is found. When this happens, the form in which the query
results are displayed comes up blank.
I want to trap this error, give the user a message box that instructs them
to change their criteria and closes the blank form.

I have tried several variations on the following code:

Private Sub Form_Load()

Dim strMsg As String, strTitle As String
Dim intStyle As Integer

If Me.RecordSource = Null Then
strMsg = "Your search returned no results. Try changing " _
& " your search criteria, then search again."
intStyle = vbOKOnly
strTitle = "Please Try Again"
MsgBox strMsg, intStyle, strTitle
DoCmd.Close acForm, "frmEmpJobMatchRslts"
End If

End Sub

Anyone have any other ideas?

Thanks... :)
 
J

John Spencer (MVP)

One method

If Me.RecordSetClone.RecordCount = 0 Then
...
End If

RecordSource will not be null (it is probably a query string). Even if it were
you have to test with IsNull(Me.RecordSource) or probably better

If Len(Me.RecordSource & vbnullstring) = 0 then
...

But that does not tell you if any records were returned, it tells you whether or
not there is a defined record source (a string value?).
 

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