[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 709
  • Last Modified:

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


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?
1 Solution
Rey Obrero (Capricorn1)Commented:

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.
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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  ""

bill201Author Commented:
yes you are right i can make a dcount

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now