Assuming that the row source type of the list box is a table, query or SQL then you can do the following:
In formB
Private Sub Form_Open(Cancel As Integer)
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset(Me.ListBox.RowSource, dbOpenDynaset)
If rst.EOF = True and rst.BOF = True Then
Cancel = -1
Else
If you have existing code put it here
End If
Set rst = Nothing
End Sub
Then in formA add to your error trapping:
If Err.Number = NumberForActionCancelledError Then
Resume Next
Else
Put your standard errortrapping code here
End If
As you can see, I don't remember the number for Action Cancelled Error. If you can't find it then let it error out once and you will see it on the error message.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.