VBA Excel - ACCESS 中的更新记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16221766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Excel - UPDATE record in ACCESS
提问by Krzysztof Stelmach
I got a problem.
我有问题。
I want to update an existing record in table in Access Database using VBA in EXCEL.
我想在 EXCEL 中使用 VBA 更新 Access 数据库表中的现有记录。
My code:
我的代码:
sqlik = "UPDATE query which works in access"
Set ZAP_QUERY2 = baza.CreateQueryDef("", sqlik)
With ZAP_QUERY2
![abc] = Edit_Form.abc.Text
![bcd] = Edit_Form.bcd.Text
![cde] = Edit_Form.cde.Text
End With
When I used sqlik = "SELECT query which works in access" it didn't make any changes. But with sqlik = "UPDATE query which works in access" it says that "Cannot find any object in this collection"
当我使用 sqlik = "SELECT query which works in access" 时,它没有做任何更改。但是使用 sqlik = "UPDATE query which works in access" 它说 "Cannot find any object in this collection"
Any ideas?
有任何想法吗?
Thanks for your help
谢谢你的帮助
采纳答案by Barranka
A solution using DAO:
使用 DAO 的解决方案:
...
dim db as DAO.Database, rec as Dao.Recordset
dim strSQL as String
Set db = OpenDatabase("c:\DatabaseFolder\YourDatabase.accdb")
strSQL = "SELECT * FROM yourTable WHERE yourField=1"
Set rec = db.OpenRecordset(strSQL, dbOpenDynaset, dbEditAdd)
With rec
.MoveFirst
![aField] = Edit_Form.abc.Text
.Update
End With
rec.Close
db.Close
...
Hope this helps you
希望这对你有帮助