?
Solved

Error Handling

Posted on 2011-05-03
3
Medium Priority
?
143 Views
Last Modified: 2012-05-11
I have a form with Goto Record Last in the On Open Event of an MDE database. Without boring you with detail, how would I display a message "No Records Available", if there are no records, rather than displaying the default error message?
0
Comment
Question by:SparkyP
3 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 35511216
Check for a Recordcount first:

If Nz(DCount("SomeField", Me.Recordsource),0) = 0 Then
  Msgbox "There are no records to show."
Else
  '/ your movelast code here
End If

Note that "SomeField" would be a field in the Form's Recordsource. In most cases, you'd use a Primary Key field for this, since it would be indexed (and therefore generally faster to process).
0
 
LVL 17

Expert Comment

by:JezWalters
ID: 35511250
Or you could just use the Recordset.RecordCount property, like this:
Private Sub Form_Open(Cancel As Integer)

    If Recordset.RecordCount = 0 Then
        MsgBox "No Records Available"
        Cancel = True
    End If

End Sub

Open in new window

0
 

Author Closing Comment

by:SparkyP
ID: 35511679
Thanks both for your quick response
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Implementing simple internal controls in the Microsoft Access application.
Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

621 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