Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

No Data and a Form

Posted on 2011-03-14
4
Medium Priority
?
204 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

604 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