Full Version: display number of records in query on a form
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
misterbill
I have a form where I want to put a sentence that says "you have (# of records from query) letters that need to be printed."

The query that I am referring to is called "letterstoprint"

How do I make it display the number of records in a query?
R. Hicks
Is this query also the recordsource for this form ???

RDH
dannyseager
msgbox "You have " & Dcount("fieldInQuery","Queryname") & " letters that need to be printed."

This is a example of doing it in a message box
misterbill
I could make it the recordsource, there is nothing elso on it because it is the main menu.
misterbill
thanks, but i don't what it to be a message box, just a field in a line of text.
R. Hicks
If there are not thousands of records return by the query .. use Danny's method.

RDH
R. Hicks
Just use the approach as the Control Source of a txtbox on the form ...
CODE
="You have " & DCount("FieldInQuery","QueryName") & " letters that need to be printed."

RDH
dannyseager
Just out of interest Ricky at what point (how many records) would you move away from a Domain Aggregate Function in favour of specifying a recordset?
R. Hicks
Normally I just open a recordset to get the value and avoid the domain aggregate functions as if they were the plague ...

RDH
misterbill
I tried typing

& DCount("letter_printed","letter_need_printing") &

into the control source for the text box, but then the form says " #Name?"

I also tried it without the & symbols, but I get the same error. Am I supposed to be putting this somewhere else?
dannyseager
Try copying exactly what ricky posted, pasting it into the control source of a text box control and then changing the

("FieldInQuery","QueryName")

to

("letter_printed","letter_need_printing")

This assumes that your Query is called letter_need_printing and that in that query you have a field called letter_printed.

Ricky, Thanks for the insight - always nice to know other peoples methods, they may be better than the ones I currently use.
misterbill
Cool! It works! Thank you both very much!
dannyseager
no problem
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.