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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I close a form, programmatically if it has no data? 1

Status
Not open for further replies.

gadsbywc

Programmer
Sep 4, 2002
14
0
0
US
I have a form that gets the data from a select query. The form is opened upon startup. I want the form to close immediately if the resulting query has no data. I have tried to use the "IsNull" on various controls of the form, with no response. The form remains open, with no data.
Here is an example:

Private Sub Form_Open(Cancel As Integer)
If IsNull(Me.Sub_To_Date) Then
DoCmd.Close
End If
End Sub

Any assistance will be greatly appeciated.

Bill Gadsby
Programmer/Analyst
bill.gadsby@co.bell.tx.us
 
check the recordcount of the recordset. for example,

If (Me.Recordset.RecordCount = 0) then
DoCmd.Close
end if

Not sure whether you need to put this in the OnLoad event of the form or the OnOpen event.
 
Thanks FancyPrrairie, It worked perfect. I put it in the OnOpen event. Kudos to you!

[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top