我開發了一個應用程序,用於在Excel 2013 Pro 32位上使用VBA從VFP空閒表和數據庫讀取數據。用於開發該應用程序的計算機已格式化。之後,我在同一臺機器上安裝了Office 2016 Pro Plus 64位。 Visual FoxPro 9.0 SP2和用於Visual FoxPro 9.0 SP 2的OLE DB提供程序也已安裝。Excel VBA App不加載數據
當我再次運行應用程序時,發出運行時錯誤3706.格式化之前,該應用程序打開數據庫和空閒表沒有任何問題。
我做了什麼?安裝和卸載VFP(和Service Pack 2)和OLE DB Provider。
爲什麼會發生這種情況?在VFP安裝期間或Office安裝過程中,我是否缺少任何文件?我是否缺少其他軟件?我正在使用Windows 7 64位專業版SP1。
在此先感謝您的回答。
UPDATE:此代碼發出錯誤
'Example for free table
Sub OpenFreeTableForReading()
Dim cnConnection As ADODB.Connection
Dim rstRecordSet As ADODB.Recordset
Dim strConnection As String, strQuery As String
Dim strErrMessage As String
Dim arrData As Variant
Dim lngX As Long
On Error GoTo ErrSub
'Setting connection object and query string command
strConnection = "Provider=VFPOLEDB.1;DataSource=C:\Path\to\TableToOpen.dbf;"
strQuery = "SELECT * FROM TableToOpen"
Set cnConnection = New ADODB.Connection
cnConnection.ConnectionString = strConnection
'This line issues runtime error 3706
cnConnection.Open
'Retrieved records are kept on an array
Set rstRecordSet = New ADODB.Recordset
With rstRecordSet
.CursorLocation = adUseClient
.LockType = adLockReadOnly
.Open strQuery, cnConnection, adOpenStatic
If Not (rstRecordSet.EOF) Then
'Disconnect the recordset
.ActiveConnection = Nothing
'Get the field count
lngX = .Fields.Count
arrData = .GetRows()
Else
'Recordset is empty; create dummy array record
ReDim arrData(0, 0)
End If
End With
'Printing data - ommited
CloseAll:
cnConnection.Close
Exit Sub
ErrSub:
strErrMessage = CStr(Err.Number) & " " & Trim(Err.Description)
MsgBox strErrMessage
Resume CloseAll
End Sub
你好。請發佈你的代碼,不可能說沒有看這個。 –