You can test for this when you first open the recordset:
Private Sub Command0_Click()
Dim dbs As DAO.Database, rst As DAO.Recordset
Dim qdf As DAO.QueryDef, prm As DAO.Parameter
' Return reference to current database.
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qry_Orders")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset()
' If both the end of file (EOF) and begin of file (BOF)
' are False, there is at least one record in the recordset.
If rst.EOF = False And rst.BOF = False Then
rst.MoveLast
Debug.Print rst.RecordCount
End If
rst.Close
Set dbs = Nothing
End Sub
--
Ken Snell
<MS ACCESS MVP>
Max said:
Ken,
Thanks for the help on this problem. Everything is working like I need
except one minor problem. When the recordset is empty (no records) I am
getting a runtime error 3021 "no current record". I have tried to place the
code DoCmd.SetWarnings False at the beginning of the code and
returning
it
to true at the end of your code. Still errors. I must be setting these
warnings incorrectly. Help??
Ken Snell said:
That means that ACCESS cannot find a field or a control on your
current
form
(the form that is running this code) named txb_MonthStartDate. Check for
typos or changes to field/control names.
--
Ken Snell
<MS ACCESS MVP>
Ken, Error
MS Access cant find the name txb_MonthStartDate you entered in the
expression.
This is beyond me...but I am paying attention!
Your query has four parameters. In order to have your code open this
query,
you must tell it what the values of those parameters are. This is done
fairly easily by changing your code to this:
Private Sub Command0_Click()
Dim dbs As DAO.Database, rst As DAO.Recordset
Dim qdf As DAO.QueryDef, prm As DAO.Parameter
' Return reference to current database.
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qry_Orders")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset()
rst.MoveLast
Debug.Print rst.RecordCount
rst.Close
Set dbs = Nothing
End Sub
--
Ken Snell
<MS ACCESS MVP>
PARAMETERS [txb_MonthstartDate] DateTime, [txb_MonthEndDate] DateTime;
SELECT Meetings.MeetingID, Meetings.ClientID, Meetings.EmployeeID,
Meetings.StartRecurRange, Meetings.EndRecurRange,
nz([Meetings].[endrecurrange],#12/31/9999#) AS ActualEndRecurRange
FROM Meetings
WHERE (((Meetings.ClientID)=[cbo_ClientName]) AND
((Meetings.StartRecurRange)<=[txb_MonthEndDate]) AND
((nz([Meetings].[endrecurrange],#12/31/9999#))>=[txb_MonthStartDate]))
OR
(((Meetings.EmployeeID)=[cbo_EmployeeName]));
Post the SQL of the query ... it appears that the query has
parameters
in
it.
--
Ken Snell
<MS ACCESS MVP>
Thanks Allen,
I Am still getting the same result. If the query was a union
query
would
that make a difference?
Specify the type of recordset, i.e.:
rst As DAO.Recordset
Include the dot:
strSQL = "SELECT qry_Orders.* FROM qry_Orders;"
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
I am experimenting with recordsets. I have cut the recordcount
example
that
is in help and pasted it into the on click event of my
form.
I
had
to
change
the query name in the strsql. I am getting an error
"Too few parameters. expected 4". Below is my code.
Private Sub Command0_Click()
Dim dbs As Database, rst As Recordset
Dim strSQL As String
' Return reference to current database.
Set dbs = CurrentDb
strSQL = "SELECT qry_Orders* FROM qry_Orders"
Set rst = dbs.OpenRecordset(strSQL)
rst.MoveLast
Debug.Print rst.RecordCount
rst.Close
Set dbs = Nothing
End Sub