A
Andibevan
I am trying to count the number of records in a query but it keeps
returning -1 when there are lots of records returned by the query.
I have tried the following approaches:-
'Debug.Print "Records = " & rst.RecordCount
'Debug.Print "Records = " & rst.GetRows
Recordcount returns -1 and getrows throws an error - "Type Mismatch".
What have I got wrong?
My total code is:-
Private Sub ExportSignoff()
Dim MyVar As Boolean
Dim strQueryName As String: strQueryName = "qry_MyTemp_1"
Dim strTemplateLoc As String: strTemplateLoc = "C:\Documents\Application
Data\Access\WIP\PVCS_CM\SMV - Sign-Off Template.xlt"
Dim rst As ADODB.RecordSet
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
'Set rst = CurrentDb.OpenRecordset(strQueryName)
cmd.CommandText = "EXECUTE " & strQueryName
cmd.CommandType = adCmdText
' Set cnn = GetNewConnection
'cnn = GetNewConnection
Set cnn = CurrentProject.Connection
cmd.ActiveConnection = cnn
Set rst = cmd.Execute
'Debug.Print "Records = " & rst.RecordCount
'Debug.Print "Records = " & rst.GetRows
' Export
' MyVar = ExportToTemplate(rst, 15, 3, m_xls, strTemplateLoc)
MyVar = ExportToExcelSignOff(rst, 15, 3, m_xls, strTemplateLoc)
' MyVar = ExportToTemplate(rst, 15, 3, m_xls)
' Disconnect recordset and return
rst.Close
cnn.Close
'rst.ActiveConnection = Nothing
Set cnn = Nothing
Set cmd = Nothing
End Sub
returning -1 when there are lots of records returned by the query.
I have tried the following approaches:-
'Debug.Print "Records = " & rst.RecordCount
'Debug.Print "Records = " & rst.GetRows
Recordcount returns -1 and getrows throws an error - "Type Mismatch".
What have I got wrong?
My total code is:-
Private Sub ExportSignoff()
Dim MyVar As Boolean
Dim strQueryName As String: strQueryName = "qry_MyTemp_1"
Dim strTemplateLoc As String: strTemplateLoc = "C:\Documents\Application
Data\Access\WIP\PVCS_CM\SMV - Sign-Off Template.xlt"
Dim rst As ADODB.RecordSet
Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
'Set rst = CurrentDb.OpenRecordset(strQueryName)
cmd.CommandText = "EXECUTE " & strQueryName
cmd.CommandType = adCmdText
' Set cnn = GetNewConnection
'cnn = GetNewConnection
Set cnn = CurrentProject.Connection
cmd.ActiveConnection = cnn
Set rst = cmd.Execute
'Debug.Print "Records = " & rst.RecordCount
'Debug.Print "Records = " & rst.GetRows
' Export
' MyVar = ExportToTemplate(rst, 15, 3, m_xls, strTemplateLoc)
MyVar = ExportToExcelSignOff(rst, 15, 3, m_xls, strTemplateLoc)
' MyVar = ExportToTemplate(rst, 15, 3, m_xls)
' Disconnect recordset and return
rst.Close
cnn.Close
'rst.ActiveConnection = Nothing
Set cnn = Nothing
Set cmd = Nothing
End Sub