In A2003, is there a method that can be used in the Open event as to the number of records in the RecordSource?
Thanks,
Bill
In A2003, is there a method that can be used in the Open event as to the number of records in the RecordSource?
Thanks,
Bill
The form method here:
http://www.baldyweb.com/RecordCounts.htm
or a DCount() against the source query. Note the load event might work better.
Paul,
Apparently, this (code) is what you had in mind? Open event for a report. DCount in fact reported the correct number of records.
Thanks,
Bill
Private Sub Report_Open(Cancel As Integer)
Me.Filter = "RetYear = " & """" & gblRetreatYear & """" & " AND Attending = true" <<<<<<<<<<Still had to set the filter
Me.FilterOn = True
strCriteria = "RetYear = " & """" & gblRetreatYear & """" & " AND Attending = true"
MsgBox DCount("[RosID]", "QRosterW/App", strCriteria)
End Sub
The DCount would work in either, I wasn't sure the recordset method would work in the open event. Because I'm lazy plus it would be more efficient, I'd set the criteria variable first and then use it for both the filter and the DCount.
Yes, once I had working code, I set a string variable to the "criteria" and used that string for both the filter and DCount.
Thanks again.
Bill
No problem Bill. It is golf weather up there yet?
Just an addendum here, if you're looking to use the DAO recordset count you'd need to the last record (rst.movelast()) then do a recordcount (rst.recordcount()) then go back to the first record (if you were going to process records one at a time).
Code:dim db as database dim rst as recordset dim iRecordcount as Long set db = currentdatabase set rst = db.openrecordset("SELECT * FROM TableName") rst.movelast irecordcount = rst.recordcount rst.close set db = nothing
I've not checked recently, but I think they'll open Graeagle on the 1st of May. At least that's when they usually open.
That was addressed in the link I posted, and yours will error on an empty recordset.Just an addendum here, if you're looking to use the DAO recordset count you'd need to the last record (rst.movelast()) then do a recordcount (rst.recordcount()) then go back to the first record (if you were going to process records one at a time).
Code:dim db as database dim rst as recordset dim iRecordcount as Long set db = currentdatabase set rst = db.openrecordset("SELECT * FROM TableName") rst.movelast irecordcount = rst.recordcount rst.close set db = nothing
Thanks. Being as how I'm dealing with the underlying RecordSource of a Report, it was far less code to simply use DCount and get a count of the primary key field at Open. Were I dealing with a RecordSet in a general module, I would certainly employ your DAO suggestion.
Thanks for your thoughts,
Bill
Yes, I didn't mention that it would bomb because he seemed to be using a recordset that had values, normally I program for a null dataset if I'm not sure what the results are going to be.
I was aware the code posted was vulnerable to error if the RecordSet was empty. But your postings here in that regard are nonetheless appreciated. As it is in the case of my report, I make it a practice of coding a "Report_NoData" in the report's code sheet and message to the user when that condition arises.
Thanks,
Bill