Fejl i SQL Count
HejFølgende kode kommer med fejlmeddelelsen (med fejl med rsData.MoveFirst):
Run-Time Error 3021: Either BOF or EOF is True, or the current record has been deleted
Sub AntalKBesøg()
'On Error Resume Next
Dim rsData As ADODB.Recordset
Dim szConnect As String
Dim szSQL As String
Dim sPath As String
Dim Tlfno As String
Dim Dato As Date, CRange As Range, C As Range, R As Range
Set CRange = ActiveWorkbook.Sheets("1. Kvartal").Range("KDatoer")
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
sPath = ActiveWorkbook.Path & "\"
' Opret forbindelse til DB
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & sPath & "gps.mdb;"
cn.Open szConnect
Tlfno = ActiveWorkbook.Sheets("1. Kvartal").Range("AB3").Value
For Each C In CRange
If C.Interior.ColorIndex <> xlNone Then
Dato = C.Value
szSQL = "SELECT * FROM KKalender WHERE Mobil = '" & Tlfno & "' AND Dato = '" & Dato & "' AND Tekst <> '""'"
Set rsData = New ADODB.Recordset
rsData.Open szSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
Do Until rsData.EOF
RecordCount = 0
rsData.MoveFirst
RecordCount = RecordCount + 1
rsData.MoveNext
Count = (RecordCount / 2)
If Count > 2 Then
C.Interior.ColorIndex = 3
ElseIf Count > 0 And Count < 3 Then
C.Interior.ColorIndex = 6
Else
C.Interior.ColorIndex = 4
End If
Loop
MsgBox Dato & " " & Count
Set rsData = Nothing
End If
Next C
' Exit Sub
'slut:
'MsgBox "Fejl i Modul 20"
'C.Interior.ColorIndex = 4
'Set rsData = Nothing
End Sub
vh Steen
