test query for eof

M

mcnews

how can i see if a query contains any records with VB and ADO.
i need to know if the query that my report uses will show any records
before i open the report.
tia,
mcnewsxp
 
G

Guest

Actually, I meant to say "Very little code requires".

This is the code I have in my reports:

'-----------------------------------
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data found for " & Forms!reportlist!cboMonth & "/" &
Forms!reportlist!cboYear & " !!"
Cancel = True
End Sub
'-----------------------------------


HTH
 
L

Linq Adams via AccessMonster.com

Also, to check for records from anywhere in code,

NumberOfRecords = dcount("[YourPrimaryKeyField]","Your Table or Query Name")

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
G

Guest

Better technique:

To minmize user confusion, put a Message Box in the No Data event of the
report so they will know what happened. You also need to cancel the no data
event or the report will open with errors (#Error) in your text boxes.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Data Found For This Report"
Cancel = True
End Sub

Then be sure you have error handling in the procedure where you open the
form to bypass error 2501. An error 2501 always is thrown when an action is
canceled.

MyReport_Exit:
On Error GoTo 0

Exit Function

MyReport_Error:

If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure WeekOfMonth of Module modDateFunctions"
End If
GoTo MyReport_Exit
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top