Solved

View SQL Count Records

Posted on 2017-05-19
3
39 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 250 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 34

Assisted Solution

by:ste5an
ste5an earned 250 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

689 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