vba 更新mysql数据库_使用VBA中的UPDATE SQL语句更新Access数据库
有人可以查看一下stSQL字符串并幫我修復我與UPDATE語句關聯的語法錯誤嗎?
運行時錯誤'-2147217900(8004e14)':UPDATE語句中出現語法錯誤。
我對SQL有一個基本的了解,似乎不明白我哪里出錯了。
如果FileName UserForm值與Access Db中的FileName字段匹配,我想更新表1的字段。
由于
Public Sub UpdateDatabaseEntry()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim stDB As String, stSQL As String, stProvider As String
Dim FileName As String
Dim Nickname As String
Dim RecipientName As String
Dim RecipientRelationship As String
Dim Summary As String
Dim Noteworthy As String
Dim PreparedBy As String
FileName = UserForm1.FileNameTextBox.Text
Nickname = UserForm1.NicknameTextBox.Text
RecipientName = UserForm1.RecipientNameTextBox.Text
RecipientRelationship = UserForm1.RecipientRelationshipComboBox.Text
Summary = UserForm1.SummaryTextBox.Text
Noteworthy = UserForm1.NoteworthyCheckBox.Value
PreparedBy = UserForm1.PreparedByTextBox.Text
stDB = "Data Source= E:\MyDb.accdb"
stProvider = "Microsoft.ACE.OLEDB.12.0"
//Opening connection to database
With cn
.ConnectionString = stDB
.Provider = stProvider
.Open
End With
//SQL Statement telling database what to do
stSQL = "UPDATE Table1" & _
"SET Nickname= '" & Nickname & "', RecipientName= '" & RecipientName & "', " & _
"RecipientRelationship= '" & RecipientRelationship & "', Summary= '" & Summary & "', " & _
"Noteworthy= '" & Noteworthy & "', PreparedBy= '" & PreparedBy & "', " & _
"WHERE FileName= '" & FileName & "'"
cn.Execute stSQL
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
總結
以上是生活随笔為你收集整理的vba 更新mysql数据库_使用VBA中的UPDATE SQL语句更新Access数据库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于vue2使用vue-awesome-
- 下一篇: mysqldump导出数据库视图_mys