List Box Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I check to see if a list box is empty?

When I open a form if the list box doesn't have any records in it I want to
display a message box. Here is what I have....

Private Sub Form_Load()
If IsNull(Me.lstDrawingNumbers) Then
MsgBox "There are no Drawing Controls for this Machine Number"
DoCmd.Close acForm, "frm_DrawingControls_Edit", acSaveNo
End If
End Sub

This code isn't working right because I get this message box even when I
know there shouldn't be any records in it.

Thanks in advance.
 
How do I check to see if a list box is empty?

When I open a form if the list box doesn't have any records in it I want to
display a message box. Here is what I have....

Private Sub Form_Load()
If IsNull(Me.lstDrawingNumbers) Then
MsgBox "There are no Drawing Controls for this Machine Number"
DoCmd.Close acForm, "frm_DrawingControls_Edit", acSaveNo
End If
End Sub

This code isn't working right because I get this message box even when I
know there shouldn't be any records in it.

Thanks in advance.

Private Sub Form_Load()
If Me!lstDrawingNumbers.ListCount = 0 Then
MsgBox "There are no Drawing Controls for this Machine Number"
DoCmd.Close acForm, "frm_DrawingControls_Edit", acSaveNo
End If
End Sub

You can also shorten the DoCmd.Close line to:
DoCmd.Close acForm, Me.Name
 
One way, use "DCount" to check to check the record count for your list box.
If it is 0 then, you have no record.
See "DCount" for more information.
 
Back
Top