Solved

No Data and a Form

Posted on 2011-03-14
4
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 58

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 58
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

717 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