In onderstaande code kreeg ik de in het onderwerp genoemde fout, hoewel volgens alles gedefinieerd was (misschien zlefs iets te veel in mijn poging het probleeem op te lossen). Zou er een reference of component onbreken? Ik heb recnet Windows opnieuw geïnstalleerd.
De code is
Sub SortX()
Dim dbsAandelen As Database
Dim rstRatios As Recordset
Dim rstSortRatios As Recordset
On Error GoTo FoutSortX
Set dbsAandelen = OpenDatabase(frmInvestor.ext(App.Path) & "DATABASE\Aandelen.mdb")
Set rstRatios = _
dbsAandelen.OpenRecordset("Ratios", dbOpenDynaset)
With rstRatios
SortOutput "Original Recordset:", rstRatios
.Sort = "Aandeel, Jaar"
' Print report showing Sort property and record order.
SortOutput _
"Recordset after changing Sort property:", rstRatios
' Open new Recordset from current one.
Set rstSortRatios = .OpenRecordset
' Print report showing Sort property and record order.
SortOutput "New Recordset:", rstSortRatios
rstSortRatios.Close
.Close
End With
dbsAandelen.Close
Exit Sub
FoutSortX:
Foutbron = Err.Number & " " & Err.Description & " in SortX"
If Foutbron <> VorigeFout Then
Call frmInvestor.WriteLOG("---< " & App.Title & " geeft >---" & Foutbron)
VorigeFout = Foutbron
Resume Next
End If
End Sub
Function SortOutput(strTemp As String, rstTemp As Recordset)
With rstTemp
Debug.Print strTemp
Debug.Print " Sort = " & _
IIf(.Sort <> "", .Sort, "[Empty]")
.MoveFirst
' Enumerate Recordset.
Do While Not .EOF
Debug.Print " " & !Aandeel & ", " & !Datum '& ", " & !Koers & ", " & [Winst / Aandeel]
frmInvestor.ResultsT.Text = frmInvestor.ResultsT.Text & " " & !Aandeel & ", " & !Datum & ", " & !Voorspelling & ", " & !SlotKoers & vbCrLf
frmInvestor.ResultsT.Text = frmInvestor.ResultsT.Text & " " & !Koers & ", "
frmInvestor.ResultsT.Text = frmInvestor.ResultsT.Text & " " & !Winst / !Aandeel & ", " & !Dividend / !Aandeel
frmInvestor.ResultsT.Text = frmInvestor.ResultsT.Text & " " & !EigenVermogen / !Aandeel & ", " & !Jaar
frmInvestor.ResultsT.Text = frmInvestor.ResultsT.Text & " " & !DividendRendement & vbCrlf
.MoveNext
Loop
End With
End Function
Public Sub SortVoorspelling()
Dim ControleMatrix(2000, 5)
Dim dbsKoersVoorspelling As Database
Dim rstKoersVoorspelling As Recordset
Dim rstSortKoersVoorspelling As Recordset
Dim strTemp as String
On Error GoTo FoutSortVoorspelling
Set dbsKoersVoorspelling = OpenDatabase(frmInvestor.ext(App.Path) & "DATABASE\KoersVoorspelling.mdb")
Set rstKoersVoorspelling = _
dbsKoersVoorspelling.OpenRecordset("KoersVoorspelling", dbOpenDynaset)
With rstKoersVoorspelling
SortOutput "Original Recordset:", rstKoersVoorspelling
.Sort = "Aandeel, Datum"
' Print report showing Sort property and record order.
SortOutput _
"Recordset after changing Sort property:", rstKoersVoorspelling
' Open new Recordset from current one.
Set rstSortKoersVoorspelling = .OpenRecordset
' Print report showing Sort property and record order.
SortOutput "New Recordset:", rstSortKoersVoorspelling
i = 1
rstSortKoersVoorspelling.index = 1
rstSortKoersVoorspelling.MoveFirst
Do While rstSortKoersVoorspelling.Recordset("SlotKoers") > 0
ControleMatrix(i, 1) = rstKoersVoorspelling("Datum")
ControleMatrix(i, 2) = rstKoersVoorspelling.Recordset("Voorspelling")
ControleMatrix(i, 3) = rstKoersVoorspelling.Recordset("SlotKoers")
ControleMatrix(i, 4) = rstKoersVoorspelling.Recordset("SlotKoers") - rstKoersVoorspelling.Recordset("Voorspelling")
ControleMatrix(i, 5) = rstKoersVoorspelling.Recordset("Aandeel")
i = i + 1
If i < rstSortKoersVoorspelling.RecordCount Then
rstSortKoersVoorspelling.MoveNext
End If
Loop
rstSortKoersVoorspelling.Close
.Close
End With
dbsKoersVoorspelling.Close
Exit Sub
FoutSortVoorspelling:
Foutbron = Err.Number & " " & Err.Description & " in SortVoorspelling"
If Foutbron <> VorigeFout Then
Call frmInvestor.WriteLOG("---< " & App.Title & " geeft >---" & Foutbron)
VorigeFout = Foutbron
Resume Next
End If
End Sub
'Note When you know the data you want to select, it's usually more efficient to create a Recordset with an SQL statement. This example shows how you can create just one Recordset and obtain the same results as in the preceding example.
Sub SortX2()
Dim dbsAandelen As Database
Dim rstRatios As Recordset
On Error GoTo FoutSortX2
Set dbsAandelen = OpenDatabase(frmInvestor.ext(App.Path) & "DATABASE\Aandelen.mdb")
' Open a Recordset from an SQL statement that specifies a
' sort order.
Set rstRatios = _
dbsAandelen.OpenRecordset("SELECT * " & _
"FROM Ratios ORDER BY Aandeel, Jaar", _
dbOpenDynaset)
EnumFields rstRatios, 12
dbsAandelen.Close
Exit Sub
FoutSortX2:
Foutbron = Err.Number & " " & Err.Description & " in SortX2"
If Foutbron <> VorigeFout Then
Call frmInvestor.WriteLOG("---< " & App.Title & " geeft >---" & Foutbron)
VorigeFout = Foutbron
Resume Next
End If
End Sub