Libreoffice VBA

出自TSK WIKI
於 2014年11月14日 (五) 08:12 由 Root​(留言 | 貢獻) 所做的修訂 (→SQL輸入範例)
跳至導覽 跳至搜尋

相容指令

Option VBASupport 1

SQL輸入範例

Option VBASupport 1
Private Sub CommandButton1_Click()
   Dim I As Integer
   Dim cn As New ADODB.Connection
   Dim strCn As String, strSQL As String    
   strCn = "Provider=sqloledb;Server=192.168.1.xx;Database=DEMO;Uid=xx;Pwd=xxxx;"    
   cn.Open strCn
   I = 2
   Do While Cells(I, 1) <> ""
       strSQL = "UPDATE PURTD set TD012='" & Range("E" & I) & "' where TD001='" & Range("A" & I) & "' and TD002='" & Range("B" & I) & "' 
       and TD003='" &    Range("C" & I) & "'"
       '底下寫執行sql語法
       cn.Execute strSQL
       I = I + 1
   Loop
   cn.Close    
   Set cn = Nothing
   MsgBox "執行完成"
End Sub

參考資料

資料庫連接