2010年6月28日 星期一

EXCEL VBA ADO CRUD的命令執行

'載入資料庫 所需引用相關變數
Dim conn2 As New ADODB.Connection
Dim rs2 As ADODB.Recordset
Dim SqlString As String
Dim i As Integer

conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.Path & "\holidaydb.MDB"


SqlString = " insert into [db](rank,name,class,fromwhen,towhen,Hcount) values('" & _
x1 & "','" & x2 & "','" & x3 & "','" & x4 & "','" & x5 & "'," & x6 & ")"

conn2.Execute (SqlString)



ret = MsgBox("請問是否寄信通知當事人?", vbYesNo, "提醒寄送電子郵件")

If ret = vbYes Then
' Call MailSend(Range("B16"))
MsgBox "您已成功新增一筆資料,並寄出通知信!"
Else
MsgBox "您已成功新增一筆資料!"
End If




End Sub

沒有留言:

張貼留言

追蹤者