Link to home
Start Free TrialLog in
Avatar of Ernest Grogg
Ernest Grogg

asked on

View SQL Count Records

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

ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ernest Grogg
Ernest Grogg

ASKER

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