Solved

Count the number of rows in a query result set

Posted on 2008-06-16
9
2,719 Views
Last Modified: 2013-11-27
I have a procedure that, depending on whether the query returns 0 rows it must do something and if it returns 1 or more, do something else.  So, how so I simply count the number of rows in a query?  I need to count the number or rows in qryPauseDurations first, if 0, then I only want to run the one query in the ElseIf portion.
Private Sub RunDurations()

'Runs queries to calculate durations

If RowCount >= 1 Then
 

        DoCmd.OpenQuery "qryPauseDurations", acViewNormal 'Need to    count number of rows in this query
 

        DoCmd.OpenQuery "qryStepDurations", acViewNormal

        DoCmd.OpenQuery "qryTaskDurations", acViewNormal

        DoCmd.OpenQuery "qryUpdatePauseStepDurations", acViewNormal

        DoCmd.Close acQuery, "qryPauseDurations"

        DoCmd.Close acQuery, "qryStepDurations"

        DoCmd.Close acQuery, "qryTaskDurations"

        DoCmd.Close acQuery, "qryUpdatePauseStepDurations"

ElseIf RowCount = 0 Then

        DoCmd.OpenQuery "qryUpdateStepOnly", acViewNormal

End If

End Sub

Open in new window

0
Comment
Question by:ssmith94015
  • 6
  • 3
9 Comments
 
LVL 75
ID: 21797183
If DCount("*", "qryPauseDurations") = 0  then

0
 
LVL 75
ID: 21797196
Private Sub RunDurations()
'Runs queries to calculate durations
If DCount("*", "qryPauseDurations") >= 0  then
 
        DoCmd.OpenQuery "qryPauseDurations", acViewNormal 'Need to    count number of rows in this query
 
        DoCmd.OpenQuery "qryStepDurations", acViewNormal
        DoCmd.OpenQuery "qryTaskDurations", acViewNormal
        DoCmd.OpenQuery "qryUpdatePauseStepDurations", acViewNormal
        DoCmd.Close acQuery, "qryPauseDurations"
        DoCmd.Close acQuery, "qryStepDurations"
        DoCmd.Close acQuery, "qryTaskDurations"
        DoCmd.Close acQuery, "qryUpdatePauseStepDurations"
Else
        DoCmd.OpenQuery "qryUpdateStepOnly", acViewNormal
End If
End Sub
0
 
LVL 75
ID: 21797211
And you won't need this:

        DoCmd.OpenQuery "qryPauseDurations", acViewNormal 'Need to    count number of rows in this query

unless you really want to open also ??

Private Sub RunDurations()
'Runs queries to calculate durations
If DCount("*", "qryPauseDurations") >= 0  then
         DoCmd.OpenQuery "qryStepDurations", acViewNormal
        DoCmd.OpenQuery "qryTaskDurations", acViewNormal
        DoCmd.OpenQuery "qryUpdatePauseStepDurations", acViewNormal
        DoCmd.Close acQuery, "qryPauseDurations"
        DoCmd.Close acQuery, "qryStepDurations"
        DoCmd.Close acQuery, "qryTaskDurations"
        DoCmd.Close acQuery, "qryUpdatePauseStepDurations"
Else
        DoCmd.OpenQuery "qryUpdateStepOnly", acViewNormal
End If
End Sub
0
 

Author Comment

by:ssmith94015
ID: 21797335
No, don't care to open, be right back.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 21797359
***I made a TYPO ***

Private Sub RunDurations()
'Runs queries to calculate durations
If DCount("*", "qryPauseDurations") > 0  then                                     '   ** HAD TYPO HERE >=0
         DoCmd.OpenQuery "qryStepDurations", acViewNormal
        DoCmd.OpenQuery "qryTaskDurations", acViewNormal
        DoCmd.OpenQuery "qryUpdatePauseStepDurations", acViewNormal
        DoCmd.Close acQuery, "qryPauseDurations"
        DoCmd.Close acQuery, "qryStepDurations"
        DoCmd.Close acQuery, "qryTaskDurations"
        DoCmd.Close acQuery, "qryUpdatePauseStepDurations"
Else
        DoCmd.OpenQuery "qryUpdateStepOnly", acViewNormal
End If
End Sub
0
 

Author Comment

by:ssmith94015
ID: 21797406
Ok, it recorgnized if it i 1 or more and runs the first if code.  However, it simply does not recognize what to do if there are 0 rows.  Let me check the query for that first.....
0
 
LVL 75
ID: 21797434
I had a typo - see my correction above  @ http:#a21797359
0
 

Author Comment

by:ssmith94015
ID: 21797545
Thanks DatabaseMX, it seems to be working.
0
 
LVL 75
ID: 21797562
you are welcome.  sorry for the typo confusion ...

mx
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now