Display a messege on a data access form.

  • Thread starter Thread starter rj
  • Start date Start date
R

rj

Hi all,

I have created a data access form (using the wizard) that diplays data
from a query.
I want the form to display a messege (eg "No data found") when there
are no records that meet the queries criterea. At the moment the page
stays blank if there are no records.

Thanks in advance..
 
rj said:
Hi all,

I have created a data access form (using the wizard) that diplays data
from a query.
I want the form to display a messege (eg "No data found") when there
are no records that meet the queries criterea. At the moment the page
stays blank if there are no records.

Build a recordset when the form opens. Count the records. If there are none,
display the message:

(aircode):

Sub Form_Open(Cancel As Integer)
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim rst As DAO.Recordset

Set db = CurrentDb
Set rst = db.OpenRecordset("form's recordsource query", dbOpenSnapshot)

With rst
. MoveLast
If .recordcount = 0 Then
MsgBox "No records, cancelling open", vbOKOnly
Cancel = True
End With

Exit_Here:
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Sub

Error_Handler:
Resume Exit_Here

End Sub

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

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

Back
Top