0
你好我很新的VBA和即時嘗試建立與密碼保護的數據庫的連接。這是我的代碼。連接到密碼保護的數據庫VBA
Sub CostEntry()
ActiveWorkbook.Sheets.Add.Name = "SAP Sheet"
sConnString = "SourceType:=0, Source:=ODBC;DSN=SAPDATA32;Description=DATA;UID=shareuser;Jet OLEDB:Database Password=1234;APP=Microsoft Office 2016;WSID=AT;DATABASE=DATA"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Open the connection and execute.
conn.Open sConnString
Set rs = conn.Execute("SELECT MBEW.BWKEY, MBEW.STPRS, MBEW.MATNR" & Chr(13) & "" & Chr(10) & "FROM SAPDATA.dbo.MBEW MBEW" & Chr(13) & "" & Chr(10) & "WHERE (MBEW.BWKEY='1010')")
' Check we have data.
If Not rs.EOF Then
' Transfer result.
ActiveWorkbook.Sheets("SAP Sheet").range("A1").CopyFromRecordset rs
' Close the recordset
rs.Close
Else
MsgBox "Error: No records returned.", vbCritical
End If
' Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing
End Sub
大部分它我也從互聯網複製我也認爲這是從stackoverflow。我收到錯誤消息「運行時錯誤」-2147467259(8000400)':找不到可安裝的ISAM「。我插入行Provider=Microsoft.ACE.OLEDB.12.0
但它只是給了我另一個錯誤消息。 Thnak你提前。
我增加它像這樣sConnString =「SourceType中:= 0,來源:= ODBC; DSN = SAPDATA32; Description = SAPDATA32; UID = shareuser; Provider ='Microsoft.ACE.OLEDB.12.0'; Jet OLEDB:Database Password = asdf; APP = Microsoft Office 2016; WSID = AT000616; DATABASE = SAPDATA「 但仍顯示錯誤消息「運行時錯誤」-2147467259(8000400)':找不到可安裝的ISAM「 –