how  to check in vba access 2010 in a form if a list box is empty

Posted on 2011-04-21
Last Modified: 2012-05-11

i have a list box (with the name outputlistbox) that the row source is activated by a recordset and i want that a certain  command button will work only if the list box is not empty and i wrote this code:
 If IsNull(Me.OutPutListbox.RowSource) Or Me.OutPutListbox = "" Then Exit Sub
but the computer allways recognize the list box that it's not empty and it's not exit the sub
why is this?
Question by:bill201
    LVL 119

    Accepted Solution


    first, what is the RowSource of the listbox? post it here

    you can use dcount() to check if rowsource will have records return or open it as recordset.
    LVL 75

    Expert Comment

    by:DatabaseMX (Joe Anderson - Access MVP)
    Also, you only need this:

     If Me.OutPutListbox = ""

    because the RowSource property is a String value, and will never be Null ... only and Empty String  ""


    Author Comment

    yes you are right i can make a dcount

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    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…

    732 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

    21 Experts available now in Live!

    Get 1:1 Help Now