Testing in vb to see if a query is empty

ChampionDuy

Registered User.
Local time
Today, 00:05
Joined
Mar 14, 2002
Messages
94
is there a way to test if a query is empty in VBA? I have a subform based on a query and if it returns no values than I would like to user to be notified by a message box.
 
If DCount("*", "[qryPartsData]") > 0 Then
Exit Sub
Else
MsgBox "There are no active records."
Exit Sub
End If

[This message has been edited by Jerry Stoner (edited 05-09-2002).]
 
I tried it but it did not work. I will show you what I did. I did it when the form is loaded. Should I put it somewhere else? Thank you for your help.

Private Sub Form_Load()

If DCount("*", "[renewquery]") > 0 Then
Exit Sub
Else
MsgBox "There are no active records."
Exit Sub
End If
End Sub
 
Youve got it in the right place.Try

If DCount("*", "[renewquery]") > 0 Then
Exit Sub
Else
MsgBox"There are no active records."
End If
End Sub
Really no reason it wont work. Make sure you know the recordset is empty.
 
thank you so much I got it to work, I just took out the exit subs and inserted my own code and it worked beautifully. Thanks again
 
This methode does not work anymore,

I get a compilation error here : "> 0 "

so I was thinking of using the count (*) function, but, and contrary to the help file, I get a syntaxt error.

Can anyone please give me a hand so I can check if a subform, based on a query is empty ?.
 
lol,

A couple of years ago this forum was upgraded and all the old posts had a lot of their characters converted to HTML. &gt is the HTML for greater than. Just replace > with >
 
as SJ has pointed out, you should replace the &gt with the greater than sign >.

Alternatively, instead of the DCount you can try it as follows:

Code:
If Me.RecordSetClone.RecordCount = 0 Then
Msgbox "Your message goes here"
End If
 

Users who are viewing this thread

Back
Top Bottom