I have a vb module which is running a saved query which references a form for use as criteria on the query. For this I use CMD.Execute as described in thread705-1328125 and this works great.
However,
I can no longer get my record count to return as anything but -1 even if I try using adOpenStatic. Am I using adOpenStatic in the incorrect location or is there a better way?
When I run queries WITH OUT criteria referencing forms I do change to adOpenStatic and get a record count everytime.
However,
I can no longer get my record count to return as anything but -1 even if I try using adOpenStatic. Am I using adOpenStatic in the incorrect location or is there a better way?
Code:
Sub find_orders_one_parameter()
Dim conn As ADODB.Connection
'Dim cat As ADOX.Catalog
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim strConn As String
Dim pl As String
Dim Record_Count As Integer
strConn = "Provider=Microsoft.jet.oledb.4.0;" & _
"Data Source=" & CurrentProject.Path & _
"\reporting.mdb"
cmd.ActiveConnection = strConn
cmd.CommandText = "[qry_with_form_criteria]"
Set rs = cmd.Execute(, Array(CDate([Forms]![frm_date_selector]![start_date]), adOpenStatic, , adCmdStoredProc))
Record_Count = rs.RecordCount
MsgBox (Record_Count)
If Not rs.EOF Then
Debug.Print rs.GetString
Else
MsgBox ("No Records Found" & Chr(13) & _
"Try another date")
End If
Set conn = Nothing
Set rs = Nothing
Set cmd = Nothing
End Sub
When I run queries WITH OUT criteria referencing forms I do change to adOpenStatic and get a record count everytime.
Code:
Set rst = New ADODB.Recordset
With rst
.Open "[qry_report_1_summary_availability]", strConn, adOpenStatic, adLockReadOnly, adCmdStoredProc
End With
Record_Count = rst.RecordCount
'MsgBox (Record_Count)