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

do not open form (or close it) if data source is empty 1

Status
Not open for further replies.

daybase

Technical User
Dec 13, 2002
115
GB
Easy one I am certain but I cannot solve it - I have a form based on a query and all works well but if the query returns no results I get a blank form - how can I prevent the form opening (or make it close) if there is no data present?

I have tried

Private Sub Form_Load()
If IsNull(me.address) Then
MsgBox "There is nothing to display"
DoCmd.Close
End If
End Sub

But no joy - any ideas?
 

What do you mean by "no joy"?
Do you get to Form_Load logic?
Do you get "There is nothing to display" message box?
What application are you using: Excel, Access, Word?


Have fun.

---- Andy
 

Maybe something like this:
Code:
Private Sub Form_Open(Cancel As Integer)
Dim Msg As String
Dim intX As Integer

intX = DCount("[YourPKField]", "YourQueryName")
  If intX < 1 Then
   Msg = "There Were No Records Returned By This Query"
   MsgBox Msg, vbOKOnly + vbInformation  
   DoCmd.Close acForm, "YourFormName"
End If
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top