This is hopefully a simple error.
I run this code and get 1 record from Debug.Print rsCount
When I run the query I get 1,007
(I copied the output of "Debug.Print queryNameOrSQL" from the immediate window - so I run the same code.)
note: I commenting out "rs.MoveLast" but still got 1.
This is a code snippet of a much larger procedure that loops thru a table and selects each "Area" and outputs to its own folder.
Help!
and thanks,
mike
Sub Test()
Debug.Print "Start: "; Now()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strArea As String
strArea = "Santa Clara Area"
Dim rsCount As Integer
Dim queryNameOrSQL As String
queryNameOrSQL = "SELECT count(Investigations1.Case_No) " & _
"FROM Cases1 LEFT JOIN Investigations1 ON Cases1.Case_No = Investigations1.Case_No " & _
"WHERE " & _
"Cases1.Case_Date_Opened Between DateSerial(2006,1,1) And DateSerial(Year(Date()),Month(Date()),0) AND " & _
"Cases1.Case_Type Not In (""Duplicate"") AND Cases1.Privileged <>""Yes"" and " & _
"Cases1.Area = " & "'" & strArea & "';"
Debug.Print queryNameOrSQL
Set db = CurrentDb
Set rs = db.OpenRecordset(queryNameOrSQL)
rs.MoveLast
rsCount = rs.RecordCount
Debug.Print rsCount
Debug.Print "End: "; Now()
End Sub
I run this code and get 1 record from Debug.Print rsCount
When I run the query I get 1,007
(I copied the output of "Debug.Print queryNameOrSQL" from the immediate window - so I run the same code.)
note: I commenting out "rs.MoveLast" but still got 1.
This is a code snippet of a much larger procedure that loops thru a table and selects each "Area" and outputs to its own folder.
Help!
and thanks,
mike
Sub Test()
Debug.Print "Start: "; Now()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strArea As String
strArea = "Santa Clara Area"
Dim rsCount As Integer
Dim queryNameOrSQL As String
queryNameOrSQL = "SELECT count(Investigations1.Case_No) " & _
"FROM Cases1 LEFT JOIN Investigations1 ON Cases1.Case_No = Investigations1.Case_No " & _
"WHERE " & _
"Cases1.Case_Date_Opened Between DateSerial(2006,1,1) And DateSerial(Year(Date()),Month(Date()),0) AND " & _
"Cases1.Case_Type Not In (""Duplicate"") AND Cases1.Privileged <>""Yes"" and " & _
"Cases1.Area = " & "'" & strArea & "';"
Debug.Print queryNameOrSQL
Set db = CurrentDb
Set rs = db.OpenRecordset(queryNameOrSQL)
rs.MoveLast
rsCount = rs.RecordCount
Debug.Print rsCount
Debug.Print "End: "; Now()
End Sub