Prevent display of blank form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a search form which requires users to enter desired criterion of
records to be displayed, another form (based on a query) would pop-up
displaying matched records. This procedure runs perfectly except for one
thing: the pop-up form (which is blank) still displays even when no record is
found. How can I prevent this? I am hoping that a message will be displayed
saying that no record is found. How can I do this? Any help would be greatly
appreciated.
 
In the search form's event which calls the popup, check the recordcount
property of the same recordset that is used by the popup.

You can even use DLookup instead of building the recordset, but generally
the recordset is faster.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
I think I stated the wrong question. What I mean is how can i display a
message box for blank query (records does not match the search string
inputted) and prevent its display including the pop-up form attached to it?
There is no other problem with the query, I just want that the program to
inform the user of an unsuccessful search and prevent the display of the
blank form. Thanks again.
 
Of course a report has the "Has Data" property. You can approximate that
same action by building a recordset and doing a recordcount in the Open
event of the form. If the recordcount = 0, then display the message box.
Something like (air code):

Sub Form_Open(Cancel As Integer)
On Error GoTo ErrorHandler ' Add an error handler

Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDB
Set rst = db.OpenRecordset("Select * ......, dbOpenDynaSet)

If rst.RecordCount = 0 Then
MsgBox "No way"
Cancel = True
Else

End If

Exit_Here:
' clean up
Exit Sub

Error_Handler:

End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top