?
Solved

View SQL Count Records

Posted on 2017-05-19
3
Medium Priority
?
71 Views
Last Modified: 2017-05-19
Hello,

How can I view the count from the code below?

??  msgbox "My Count is " & mycount

Dim mycount As String
mycount = "SELECT Count(*) AS MyCount " & vbCrLf & _
"FROM BackgroundCheck " & vbCrLf & _
"WHERE (((BackgroundCheck.Background) Not Like ""Access Denied"" And (BackgroundCheck.Background)=""Waiver Denied"" And (BackgroundCheck.Background)=""Waiver Granted"") AND ((BackgroundCheck.DateNeededCheck)<DateAdd(""yyyy"",-1,Date()-1)));"

Open in new window

0
Comment
Question by:Ernest Grogg
[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 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 total points
ID: 42142769
try this
sub MyCount()
dim xCount as integer
xCount=Dcount("*","BackgroundCheck","[Background] In('Waiver Denied','Waiver Granted') And [DateNeededCheck] <DateAdd('yyyy',-1,Date()-1)")

msgbox "My count is " & xCount

end sub
0
 
LVL 35

Assisted Solution

by:ste5an
ste5an earned 1000 total points
ID: 42142780
E.g.

Dim Sql As String  
Dim rs As DAO.Recordset
Dim myCount As Long
Dim Condition As String

Sql = _
  "SELECT Count(*) " & _
  "FROM BackgroundCheck " & _
  "WHERE Background IN ( 'Waiver Denied', 'Waiver Granted' ) " & _
  "AND DateNeededCheck <DateAdd('yyyy',-1,Date()-1);" 

Set rs = CurrentDb.OpenRecordset(Sql)
myCount = rs.Fields(1).Value
 
Condition = _
  "Background IN ( 'Waiver Denied', 'Waiver Granted' ) " & _
  "AND DateNeededCheck <DateAdd('yyyy',-1,Date()-1);" 
  
myCount = DCount("*", "BackgroundCheck", Condition)

Open in new window

0
 

Author Comment

by:Ernest Grogg
ID: 42142925
Great Solutions!

Thanks,

I had to change ste5an's just a bit to get it to work:  (the condition had a syntax error, so I removed and changed the fields to 0)

I also had the string slightly wrong, so this below I had to have it looking just for the 1 .  

AND

Rey Obrero (Capricorn1) was good to go also...granting both as great solutions.

Dim Sql As String
Dim rs As DAO.Recordset
Dim mycount As Long

Sql = _
  "SELECT Count(*) " & _
  "FROM BackgroundCheck " & _
  "WHERE Background IN ( 'Access Granted' ) " & _
  "AND DateNeededCheck <DateAdd('yyyy',-1,Date()-1);"

Set rs = CurrentDb.OpenRecordset(Sql)
mycount = rs.Fields(0)
 

MsgBox "Total Record needing moved: " & mycount

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

650 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