I am having some trouble with opening recordsets. I have used code
more or less straight from the access help. But still I am getting
some errors. I am unable to work out what exactly I am doing wrong.
1.When I try the following code it gives the error message "compile
error- type mismatch" on the last line. ( I have seen in past postings
that this error is usually because of DAO/ADO mismatch. Is the
recordsource for forms in Access 2000 by default ADO?)
Dim dbsTemp As DAO.Database
Dim rstTemp As DAO.Recordset
Set dbsTemp = OpenDatabase("C:\Documents and Settings\j\My
Documents\db1.mdb")
Set rstTemp = dbsTemp.OpenRecordset( "SELECT * FROM Table1")
With rstTemp | This is just to test whether it
.MoveLast | opens the recordset. I get a count of 6
.MoveFirst | which is the number of records in the table
MsgBox (rstTemp.RecordCount)
End With
Me.RecordSource = rstTemp -> the error appears here
2. In the following code, the record count is shown as "–1". Thias is
the same table as above, containing 6 records
Dim rst As New ADODB.Recordset
Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection
Dim strSource As String
strSource = "SELECT * FROM Table1;"
rst.Open strSource, cnn, adOpenDynamic
If rst.EOF Then
MsgBox ("No records")
Exit Sub
Else
rst.MoveLast
rst.MoveFirst
MsgBox (rst.RecordCount)
End If
Sunil Korah