I have a query (qryTexShipped) with a Criteria (#3/16/2012#) for a date field, and a Criteria (Like "CM*") for a text field. I run the query directly and see 11 records.
But in my VBA code when I try what you see listed below, the RecordCount is 0. I have done this sort of thing, successfully, many times in other programs, so am stumped as to why the problem occurs now. I am using Access 2010 under Windows 7. I have the following references set:
Visual Basic For Applications
Microsoft Access 14.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.8 Library
Microsoft ADO Ext. 2.8 for DDL and Security
Microsoft Scripting Runtime
Microsoft DAO 3.6 Object Library
Microsoft Excel 14.0 Object Library
Private Sub btnHarvestShippingFiles_Click()
Dim RowKtr As Long
Dim ar() As arrShipped
Dim Ktr As Integer
Dim Ck As String
Dim TotRecs As Integer
Dim rstADO As New ADODB.Recordset
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
'GetShippingData:
rstADO.Open "qryTexShipped", cnn, adOpenStatic, adLockOptimistic, adCmdTableDirect
TotRecs = rstADO.RecordCount
MsgBox TotRecs
...
But in my VBA code when I try what you see listed below, the RecordCount is 0. I have done this sort of thing, successfully, many times in other programs, so am stumped as to why the problem occurs now. I am using Access 2010 under Windows 7. I have the following references set:
Visual Basic For Applications
Microsoft Access 14.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.8 Library
Microsoft ADO Ext. 2.8 for DDL and Security
Microsoft Scripting Runtime
Microsoft DAO 3.6 Object Library
Microsoft Excel 14.0 Object Library
Private Sub btnHarvestShippingFiles_Click()
Dim RowKtr As Long
Dim ar() As arrShipped
Dim Ktr As Integer
Dim Ck As String
Dim TotRecs As Integer
Dim rstADO As New ADODB.Recordset
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
'GetShippingData:
rstADO.Open "qryTexShipped", cnn, adOpenStatic, adLockOptimistic, adCmdTableDirect
TotRecs = rstADO.RecordCount
MsgBox TotRecs
...