query should say-no rows!

  • Thread starter Thread starter Shivalee Gupta via AccessMonster.com
  • Start date Start date
S

Shivalee Gupta via AccessMonster.com

I have a query which I run on the click of a command in a form. I would
like to write a code which does this:
Whenever the query is displaying no rows, rather than displaying an empty
page, it should display that no rows matched to the query.
Can anyone help me?
 
****Untested****
If DCount("*", "QueryName") Then
MsgBox "No rows returned"
Else ' Some rows returned
....
End If
********
 
hello.
this is my sub:

Private Sub Command02_Click()
On Error GoTo Err_Command02_Click

Dim stDocName As String

stDocName = "displaying Tcode from uname"
DoCmd.OpenQuery stDocName, acNormal, acEdit
If DCount("*", "displaying tcode from uname") = 0 Then
MsgBox "no rows"
End If

Exit_Command02_Click:
Exit Sub

Err_Command02_Click:
MsgBox Err.Description
Resume Exit_Command02_Click

End Sub

Your msgbox is working. but it is still opening the blank query.
I have tried using
cancel=true and
docmd.close
but both are not working.
can you suggest, please.
thanks both of you,
(I am using onnodata in case of a report.)
shivalee
 
No, the OpenQuery should be in the Else part of your If statement.

Try:

stDocName = "displaying Tcode from uname"
If DCount("*", "displaying tcode from uname") = 0 Then
MsgBox "no rows"
Else
DoCmd.OpenQuery stDocName, acNormal, acEdit
End If
 
Back
Top