vba - Trying to update table in ms Access using VBA but getting failed , used multiple option but table not getting updated
问题描述
Trying to update table in ms Access using VBA but getting failed , used multiple option but table not getting updated
Dim bod As Date
Dim assets As String
Dim emname As String
Dim ecode As String
Dim Astatus As String
Astatus = "SOLD"
msaved = True
DoCmd.SetWarnings False
bod = Me.datetime.Caption
price1k = Me.cmbox1_1AID.Value
emname = Me.empname.Value
ecod = Nz(Me.code.Value, 0)
//tried using this but not getting updated no error
DoCmd.RunSQL "UPDATE [Asset E7450 List] SET Code = '" & ecod & "',[Date & Time] ='" & bod & "' ,Status ='" & Astatus & "',[Sold To] ='" & empname & "', where Asset-ID ='" & price1k & "'"
// Tried using this no update no error
CurrentDb.Execute "UPDATE [Asset E7450 List] SET Code = '" & ecod & "',[Date & Time] ='" & bod & "' ,Status ='" & Astatus & "',[Sold To] ='" & empname & "', where Asset-ID ='" & price1k & "'"
// Tried this method no data update no error
Dim strSQL As String
strSQL = "UPDATE [Asset E7450 List] SET Code = '" & ecod & "',[Date & Time] ='" & bod & "' ,Status ='" & Astatus & "',[Sold To] ='" & empname & "', where Asset-ID ='" & price1k & "'"
DoCmd.RunSQL strSQL
MsgBox " Booking Request Accepted ", vbInformation
解决方案
If [Date & Time] is a date/time type field, use #
delimiter instead of '
. If field is a number type, don't use any delimiter.
Remove the comma in front of WHERE clause.
Need [ ]
around Asset-ID field name because of the hyphen.
Advise not to use spaces nor punctuation/special characters in naming convention.
推荐阅读
- python - 如何将xml文件数据导入csv?
- git - 获取合并提交的 git diff 输出结果
- php - 如何显示对应于特定 $_SESSION 变量的条目
- python-3.x - 如何每隔一行写入文件?
- xpath - 与 xpath 和 string() 匹配的不同数量
- android - Android 屏幕阅读器在定位颤振抽屉时显示“关闭”
- excel - 提供列内的总和,移动到同一行列上的下一个标题名称,复制粘贴
- excel - Excel 公式中空格/空白字符 (" ") 的长度
- css - React - 输入上的伪元素根本没有呈现
- python - 检查目标时出错:预期 dense_24 有 3 个维度,但得到了形状为 (3283, 1) 的数组