Error Handling

Posted on 2011-05-03
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?
Question by:SparkyP
    LVL 84

    Accepted Solution

    Check for a Recordcount first:

    If Nz(DCount("SomeField", Me.Recordsource),0) = 0 Then
      Msgbox "There are no records to show."
      '/ 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).
    LVL 17

    Expert Comment

    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


    Author Closing Comment

    Thanks both for your quick response

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now