Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

assigning result of SQL select to a label

Status
Not open for further replies.

toon10

Programmer
Mar 26, 2004
303
DE
It’s been years since I did Access programming so apologies if this is remarkably simple! I have an SQL statement which produces a count figure (in this case 312.) All I want to do is assign this SQL “SELECT DISTINCT Count(tblSales.[Latest Price]) AS LPrice FROM tblSales;” result to a form label.

I used to do this sort of thing in my sleep but I can’t seem to get it working!

Thanks
 
If VBA for access:
Me![label name].Caption = DCount("[Latest Price]", "tblSales")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the reply.

Unfortunately, the text box displays the "#Name?" text rahter than the result. That will also include duplicates so I need to use the DISTINCT keyword somewhere.

Thanks
 
My mistake, slight typo. I think thats OK!

Cheers
 
Actually, that still returns a count of all records and not DISTINCT.
 
JetSQL lacks the Count(DISTINCT ...) aggregate function.
You may try this:
Dim rs As DAO.Recordset, sql As String
sql = "SELECT Count(*) FROM (SELECT DISTINCT [Latest Price] FROM tblSales) D"
Set rs = CurrentDb.OpenRecordset(sql)
Me![label name].Caption = rs(0)
rs.Close
Set rs = Nothing


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That does the trick.

Thanks for the help, much appreciated.
Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top