Full Version: DCount
UtterAccess Forums > Microsoft® Access > Access Forms
aburl81
I am having some trouble with the DCount function. My form record source is a query that selects a Fk and pulls only those records of the selected FK. On the forms current event I am using this to count the number of records:
e![RecordCount] = "Question " & (recClone.AbsolutePosition + 1) & " of " & _
DCount("QuestionID", "tblQuestions")
this works fine except it counts all the records in the table and not just the set of records which were selected in the query, when I change "tblQuestions" to the name of my query "qryQuestions" I get nothing. How can I change this to count only those records selected from the query?
Adan
ScottGem
Does the Query have a field named QuestionID? Also try:
Count("[QuestionID]", "tblQuestions")
aburl81
WOW that was quick! it works....I didn't know I needed the brackets around "QuestionID". Thanks a bunch
ScottGem
glad to assist
LPurvis
That worked for you???

You're wanting to limit the count to the number of records presented where? In the currently open form?
But the form is based on a query - not a table.
So
DCount("*", "qryQueryName")
would surely be what you need.

However...
Owouldn't do that.
You already have the records loaded in the form. Don't use the DCount to check the database...

CODE
With Me.Recordset.Clone
nbsp;   .MoveLast
    Me![RecordCount] = "Question " & Me.Recordset.AbsolutePosition + 1 & " of " & .RecordCount
End With


But I'd advise against a control (even an unbound one) named RecordCount. Call it txtRecordCount or whatever...
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.