Laufzeitfehler -2147467259
30.06.2014 08:33:03
Tom
ich bekomme immer wieder mal den Laufzeitfehler -2147467259
Im Debug Modus wird mir die Zeile cnMDB.Open sAdoConnectString markiert.
Hat jemand eine Idee woher das kommt? Irgendwie hat der ODBC-Treiber einen schlag oder?!
Fehlermeldung:
Option Explicit
'ab xl2007
Private Const cProvider As String = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ="
Private cnMDB As Object ' oder ADODB.Connection -> 'Verweis auf: Microsoft ActiveX Data Objects ...
Private adoRS As Object ' oder ADODB.Recordset -> 'Verweis auf: Microsoft ActiveX Data Objects ...
Private Sub Close_Datenbank()
On Error Resume Next
adoRS.Close
Set adoRS = Nothing
cnMDB.Close
Set cnMDB = Nothing
End Sub
Private Sub ADO_Connect(strFile$)
Dim sPath$, sAdoConnectString$
Set cnMDB = CreateObject("ADODB.Connection") '
'1. Version so
sAdoConnectString = cProvider & strFile
cnMDB.Open sAdoConnectString
End Sub
Private Sub Oben_Recordset(ByVal strSQL$)
Set adoRS = CreateObject("ADODB.Recordset")
With adoRS
.ActiveConnection = cnMDB
.CursorLocation = 3
.CursorType = 2
.LockType = 3
.Open strSQL
End With
End Sub
Function oExAbfrage(ByVal strFile$, ByVal sTabAndRange$, Optional booCloseDB As Boolean = False)Dim strSQL$, arValues(), n&, nCounter&
If cnMDB Is Nothing Then ADO_Connect strFile
If cnMDB Is Nothing Then GoTo ErrorConnect 'Error
strSQL = "SELECT * FROM [" & sTabAndRange$ & "]"
If adoRS Is Nothing Then
Oben_Recordset strSQL
If adoRS Is Nothing Then GoTo ErrorConnect 'Error
End If
With adoRS
If Not .BOF Then
ReDim Preserve arValues(1 To 1, 1 To .Fields.Count)
For n = 0 To .Fields.Count - 1
If .Fields(n) "" Then nCounter = nCounter + 1: arValues(1, nCounter) = .Fields(n).Value
Next n
ReDim Preserve arValues(1 To 1, 1 To nCounter)
oExAbfrage = Application.Transpose(arValues)
End If
End With
If booCloseDB Then Close_Datenbank
Exit Function
ErrorConnect:
Close_Datenbank
oExAbfrage = "Error"
End Function
gruß Tom