「Libreoffice VBA」:修訂間差異

出自TSK WIKI
跳至導覽 跳至搜尋
Root​(留言 | 貢獻)
無編輯摘要
Root​(留言 | 貢獻)
第11行: 第11行:
     I = 2
     I = 2
     Do While Cells(I, 1) <> ""
     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) & "'"
         strSQL = "UPDATE PURTD set TD012='" & Range("E" & I) & "' where TD001='" & Range("A" & I) & "' and TD002='" & Range("B" & I) & "'  
        and TD003='" &    Range("C" & I) & "'"
         '底下寫執行sql語法
         '底下寫執行sql語法
         cn.Execute strSQL
         cn.Execute strSQL
第20行: 第21行:
     MsgBox "執行完成"
     MsgBox "執行完成"
  End Sub
  End Sub
==參考資料==
[http://www1.cpshs.hcc.edu.tw/leson/learn/ASP%E8%B3%87%E6%96%99%E5%BA%AB/new_page_8.htm 資料庫連接]

於 2014年11月14日 (五) 08:12 的修訂

相容指令

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

參考資料

資料庫連接