No search results equalls debug error

M

midalwhat

I am fairly certain the code I have used has created the problem so
will include it:

I have created a simple progress tracking database that lets multiple
users search for records. I created a simple 2 criteria search form
which opened a query. I then changed it to open a form which views the
query as it is easier to lock to prevent changes to the data. No
problems until now.

Private Sub OK_Click()
Me.Visible = False
DoCmd.OpenForm "SRF", acViewNormal, acEdit
DoCmd.Close acForm, "Search"
End Sub

I then added code to the form that shows a box saying there are no
results rather than a blank page which doesn't open the 'SRF' form.

Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "No results found", vbOKOnly, "No records found"
End If
End Sub


Once this runs it throws me back to the original code to debug as it
didn't open the 'SRF' form. I know I am doing something very simple
wrong as I am very new to all this and can guarantee I have used code
for things far simpler than what I am trying to do.

If possible I would like a search that has no results to throw up the
error message and re-open the original search form. Would this also
reslut in a debug error as the SRF form wouldn't be opened? Is it
simple a case of addingthis code to the no results code?

DoCmd.OpenForm "Search", acViewNormal
 

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