Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stop form from opening if listbox empty 1

Status
Not open for further replies.

3699wat

Technical User
Sep 30, 2002
28
US
Need help with the code on the on click event of a command button on formA to stop formB from opening if the listbox on formB is empty

 
You can use if Dcout("field on listbox", "table/query name") =0 then stop open form.
 
Hi!

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.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top