Solved

No Data and a Form

Posted on 2011-03-14
4
195 Views
Last Modified: 2012-05-11
Experts,

I see that a form does not have a "On No Data" event like a report has.  
How can I craft an On No Data for a  form?

thank you.

this is what I use for a report:
Private Sub Report_NoData(Cancel As Integer)

    MsgBox "No Data"
    Cancel = True
End Sub
0
Comment
Question by:pdvsa
  • 2
4 Comments
 
LVL 8

Expert Comment

by:hello_everybody
ID: 35127974
you can check recordset count on form's open event, and cancel it:


if Me.Recordset.RecordCount = 0 then
Cancel = true
end if

DoCmd.OpenForm in that case will produce runtime error which you have to handle


http://www.pcreview.co.uk/forums/no-data-form-open-t3987721.html
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 35127979

In the forms OnLoad event you could do:

  If Me.recordsetclone.RecordCount = 0 then
     Msgbox "No data"
     Docmd.close  acForm, Me.Name
  End If

JimD.
0
 
LVL 57
ID: 35128026
<<on form's open event>>

  Really don't want to use OnOpen for this; that's a little too early and might be hit or miss.  Your not guaranteed that the forms recordset has been loaded until you hit OnLoad.

JimD.
0
 

Author Closing Comment

by:pdvsa
ID: 35128226
Perfect.  thank you
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question