cancel form open if listbox is empty

  • Thread starter Thread starter deb
  • Start date Start date
D

deb

I have an unbound list box called lstFacts on a form called fProject.
I also have a button called btnProjReview that opens another form.

If the listbox is empty, I would like a msg box to pop up saying "Cannot
open form if Facts list is empty, and cancel the opening of the ProjReview
form.

How can this be done?

Thanks
 
Deb

If your code behind the command button opens another form, one approach
would be to embed THAT code within an If...Then statement, and test whether
the listbox has a selected value to determine whether to fire the code to
open the form.

You could also add in code to pop up a messagebox.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Try this
Private Sub btnProjReview_Click()
If Not IsNull(Me!lstFacts) Then
DoCmd.OpenForm "YourFormName", , , "A Condition if needed"
Else
MsgBox "Cannot open form if Facts list is empty"
Exit Sub
End Sub
 
I forgot to end the if.
Private Sub btnProjReview_Click()
If Not IsNull(Me!lstFacts) Then
DoCmd.OpenForm "YourFormName", , , "A Condition if needed"
Else
MsgBox "Cannot open form if Facts list is empty"
Exit Sub
End If
End Sub
 
Back
Top