I am using VB6 with Access 2000. I am opening as DAO and reading records from a file. As I find the student record it performs the following lookup to locate records in a bound data control recordset. What is happening though is the code as is produces and error 3420 (Object invalid or not set) with the DB.Close. Without the close it appears to leave the database open and I get and error 3048 (Can't open any more databases) after a number of records have been read.
Dim ParmQD As QueryDef
Dim ParmRS As Recordset
Dim DB As Database
Dim SQL1 As String
On Error GoTo errorhandler
strDB = stdDisp.student.DatabaseName
If stdDisp.stud_id.Text <> "" Then
Set DB = Workspaces(0).OpenDatabase(strDB, , , "MS Access;pwd=windjammer")
SQL1 = "PARAMETERS [Student Id] Double; " _
& " SELECT * FROM cogat_scores " _
& " WHERE (ID = [Student Id]) " _
& " order by test_year ASC; "
Set ParmQD = DB.CreateQueryDef("", SQL1)
ParmQD.Parameters![Student ID] = stdDisp.stud_id.Text
Set ParmRS = ParmQD.OpenRecordset(dbOpenDynaset)
Set stdDisp.cogat_scrs.Recordset = ParmRS
DB.Close
Set DB = Nothing
Set ParmQD = Nothing
Set ParmRS = Nothing
' Set record slide to be invisible
stdDisp.cogat_scrs.Visible = False
' Check to see how many records were found
stdDisp.cogat_scrs.Recordset.MoveLast
rcdcnt = stdDisp.cogat_scrs.Recordset.RecordCount
If rcdcnt > 1 Then
stdDisp.cogat_scrs.Visible = True
End If
End If
exitsub:
Exit Sub
errorhandler:
Select Case Err.Number ' Evaluate error number.
Case 3021 ' No Current Record
Resume exitsub
Case Else
errprmpt = MsgBox(Err.Description, vbOKOnly, Err.Number)
End Select
Dim ParmQD As QueryDef
Dim ParmRS As Recordset
Dim DB As Database
Dim SQL1 As String
On Error GoTo errorhandler
strDB = stdDisp.student.DatabaseName
If stdDisp.stud_id.Text <> "" Then
Set DB = Workspaces(0).OpenDatabase(strDB, , , "MS Access;pwd=windjammer")
SQL1 = "PARAMETERS [Student Id] Double; " _
& " SELECT * FROM cogat_scores " _
& " WHERE (ID = [Student Id]) " _
& " order by test_year ASC; "
Set ParmQD = DB.CreateQueryDef("", SQL1)
ParmQD.Parameters![Student ID] = stdDisp.stud_id.Text
Set ParmRS = ParmQD.OpenRecordset(dbOpenDynaset)
Set stdDisp.cogat_scrs.Recordset = ParmRS
DB.Close
Set DB = Nothing
Set ParmQD = Nothing
Set ParmRS = Nothing
' Set record slide to be invisible
stdDisp.cogat_scrs.Visible = False
' Check to see how many records were found
stdDisp.cogat_scrs.Recordset.MoveLast
rcdcnt = stdDisp.cogat_scrs.Recordset.RecordCount
If rcdcnt > 1 Then
stdDisp.cogat_scrs.Visible = True
End If
End If
exitsub:
Exit Sub
errorhandler:
Select Case Err.Number ' Evaluate error number.
Case 3021 ' No Current Record
Resume exitsub
Case Else
errprmpt = MsgBox(Err.Description, vbOKOnly, Err.Number)
End Select