I just realized that we're getting side-tracked on the RecordCount
question. Your problem actually isn't a RecordCount problem at all. Your
query will *always* return one record, even if there are no records in
the table - it will return Null in that situation. So ...
Public Sub HasRecords()
Dim rst As New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.Source = "SELECT Max([TestDate]) AS TheDate FROM tblTest"
.Open
If IsNull(.Fields("TheDate")) Then
MsgBox "There aren't any records - or at least none with a
date entered"
Else
MsgBox "The date is: " & .Fields("TheDate")
End If
.Close
End With
End Sub
--
Brendan Reynolds (MVP)
scott said:
can you send a full function with code like mine that did the job? I
can't find an example of using a dsn that referenced a front end file,
but with linked tables and front end local tables.
"Brendan Reynolds" <brenreyn at indigo dot ie> wrote in message
If you *only* want to know whether the recordset returns records or
not, you can test the BOF and EOF properties. If both are True, the
recordset doesn't return any records, otherwise it does ...
rst.Open
If (rst.BOF And rst.EOF) Then
'no records
Else
'records
End If
--
Brendan Reynolds (MVP)
I get an error saying "Rowset does not support fetchuing backward "
when trying your method.
A recordset is not "filled" with all records until you actually access
those records. Thus, add a step to move to the last record before you
get the record count.
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open "Select Max([myDateField]) From t_import"
rs.MoveLast
Debug.Print rs.RecordCount
rs.Close
Set rs = Nothing
--
Ken Snell
<MS ACCESS MVP>
Below returns -1 for the record count when it should report a 1 for
the Max Date field when the table has data. I need the RecordCount
property to return the correct number of records because I need to
test the table to see if it actually has any records.
Any ideas?
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
rs.Open "Select Max([myDateField]) From t_import"
Debug.Print rs.RecordCount
rs.Close
Set rs = Nothing