Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get record count using SQL statement in Access

Posted on 2008-09-30
6
Medium Priority
?
994 Views
Last Modified: 2013-11-28
I would like to find the 'count' of the field 'QCReportNo' and save it in a variable.
I've attached my code but can't even get it to compile.  I get the error...
    Wrong number of arguments or invalid property assignment.
strSQL = "SELECT Count(tblDaily.QCReportNo) "
strSQL = strSQL & "FROM tblDaily INNER JOIN (tblInstrumentsUsed INNER JOIN tblInstrumentsDesc ON tblInstrumentsUsed.InstrumentDescId = tblInstrumentsDesc.InstrumentDescId) ON tblDaily.QCReportNo = tblInstrumentsUsed.QCReportNo "
strSQL = strSQL & "WHERE (((tblDaily.QCReportNo)=[Forms]![frmPrevDailyDFT]![cboQCRptNo]))"
DoCmd.RunSQL (strSQL)
dblCount = Count(QCReportNo)

Open in new window

0
Comment
Question by:BobRosas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:aaronakin
ID: 22607625
Try giving the counted value an alias.  i.e. "SELECT Count(tblDaily.QCReportNo) AS QCReportNoCount "

Then, try assigning dblCount = QCReportNoCount.
0
 

Author Comment

by:BobRosas
ID: 22607718
Thank you so much for your quick response.  I've changed my code and reposted.  Now I get the message 'Variable not defined" for the alias value.  However it could be related to my statement.
I tried running the code with the last line commented out and it compiles but on the
Do.Cmd.RunSQL (strSQL)
I get the error...
A RunSQL action requires an argument consisting of an SQL statement.
If I just want a count do I even need the do.cmd line?
Thanks in advance.
    strSQL = "SELECT Count(tblDaily.QCReportNo) As RptNoCount "
    strSQL = strSQL & "FROM tblDaily INNER JOIN (tblInstrumentsUsed INNER JOIN tblInstrumentsDesc ON tblInstrumentsUsed.InstrumentDescId = tblInstrumentsDesc.InstrumentDescId) ON tblDaily.QCReportNo = tblInstrumentsUsed.QCReportNo "
    strSQL = strSQL & "WHERE (((tblDaily.QCReportNo)=[Forms]![frmPrevDailyDFT]![cboQCRptNo]))"
    DoCmd.RunSQL (strSQL)
    dblCount = RptNoCount  

Open in new window

0
 

Author Comment

by:BobRosas
ID: 22607828
I changed my SQL code and added a 'group by' because I think it needs it to give me the right count.  But the errors are the same as above.

strSQL = "SELECT Count(tblDaily.QCReportNo) AS RptNoCnt "
     strSQL = strSQL & "FROM tblDaily INNER JOIN (tblInstrumentsUsed INNER JOIN tblInstrumentsDesc ON tblInstrumentsUsed.InstrumentDescId = tblInstrumentsDesc.InstrumentDescId) ON tblDaily.QCReportNo = tblInstrumentsUsed.QCReportNo "
     strSQL = strSQL & "GROUP BY tblDaily.QCReportNo "
     strSQL = strSQL & "HAVING (((tblDaily.QCReportNo)=[Forms]![frmPrevDailyDFT]![cboQCRptNo]))"

Open in new window

0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 11

Expert Comment

by:aaronakin
ID: 22607844
It's a while since I last used Access.  Check out this article though and see if it helps you.
0
 
LVL 11

Accepted Solution

by:
aaronakin earned 500 total points
ID: 22607845
0
 

Author Closing Comment

by:BobRosas
ID: 31501634
Yes that helped.  I got it working
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question