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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值