Message 1 of 16
How can this be true??!?

Not applicable
09-30-2004
10:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Simply put, I'm opening a database, searching through a table and then
showing a message box with 2 numbers, one of which is the RecordCount of the
RecordSet, but I'm being told by the computer that I have -1 for a
RecordCount.
I've using ADO...
Here's the code...
The first sub opens the database
The second sub closes the database
The third sub tells me I have -1 counts
'=================================================
Public Cnxn As ADODB.Connection
Public strCnxn As String
Public rstLayers As ADODB.Recordset
Public Const AppName = "VBA::Set Layer"
'=================================================
Public Sub OpenDatabase()
On Error GoTo ErrMsg
' Open connection
strCnxn = "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=S:\CADDStds\Menus\Data\Layers.mdb"
Set Cnxn = New ADODB.Connection
Cnxn.Open strCnxn
Exit Sub
ErrMsg:
MsgBox "An error has occurred in modMain.OpenDatabase" & vbCrLf &
Err.Number & ":" & Err.Description, vbCritical + vbOKOnly, AppName
End Sub'=================================================
Public Sub CloseDatabase()
On Error Resume Next
rstLayers.Close
On Error Resume Next
Cnxn.Close
End Sub
'=================================================
Sub CountCurrent()
OpenDatabase
Dim rsSearch As Recordset
Dim SQL As String
Set rsSearch = New ADODB.Recordset
SQL = "SELECT * FROM Layers ORDER BY Layer_Name"
rsSearch.Open SQL, Cnxn
MsgBox rsSearch.RecordCount 'shows that I have -1 records??!?
Dim i As Integer
i = 0
Do Until rsSearch.EOF
If rsSearch!current = True Then i = i + 1
rsSearch.MoveNext
Loop
MsgBox "Of the " & rsSearch.RecordCount & " files in the Layers table, "
& i & " are currently being used."
CloseDatabase
End Sub
'=================================================
--
I support two teams: the Red Sox and whoever beats the Yankees.