How to use SELECT COUNT on form

Ben2k

Board Regular
Joined
Oct 16, 2002
Messages
77
I have a form and a text box

I want to use the following SQL command to populate the textbox

=(SELECT COUNT FROM [qry_summary_getalldeals])

qry_summary_getalldeals is a query

When I run the form it just displays #Name?, presume syntax must be wrong?

Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You can't just put a query into a textbox like that.

Try looking at the DCOUNT, DSUM etc functions.

e.g. =DCOUNT("*", "qry_summary_getdeals")
 
Upvote 0
Sorry I meant a listbox

SELECT COUNT Qry_Summary_GetAllDeals.Type FROM Qry_Summary_GetAllDeals;

This gives an error "syntax error (missing operator)"
 
Upvote 0
I'm sorry but I don't quite understand what you are trying to do?

What is it you actually want in the listbox?

Why not try using the Query Builder to create a query to populate it?

i.e. On the Property sheet for the control goto the Data tab, select Row Source Type =Table/Query and then goto Row Source...
 
Upvote 0
Thanks Norie, just sussed it out myself, was getting confused as I didn't realise you could bind individual queries to controls

This syntax works

SELECT COUNT([Qry_Summary_GetAllDeals.Type]) FROM Qry_Summary_GetAllDeals

However when I try to add a where clause as below it says "invalid bracketing"

SELECT COUNT([Qry_Summary_GetAllDeals.Type]) FROM Qry_Summary_GetAllDeals WHERE ([qry_summarygetalldeals.type]='trade');
 
Upvote 0
I was using the query builder, but then switching to SQL view to add the COUNT bit, not sure what problem was but I rebooted PC and it worked fine then.
 
Upvote 0
was using the query builder, but then switching to SQL view to add the COUNT bit

Why did you do that?

You can do counts, sums etc in the query builder.

Just right click and select Totals.
 
Upvote 0

Forum statistics

Threads
1,221,783
Messages
6,161,915
Members
451,730
Latest member
BudgetGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top