3

我有问题。

我想在 EXCEL 中使用 VBA 更新 Access 数据库中表中的现有记录。

我的代码:

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

当我使用 sqlik = "SELECT query which works in access" 时,它没有进行任何更改。但是使用 sqlik = "UPDATE query which works in access" 它说 "Cannot find any object in this collection"

有任何想法吗?

谢谢你的帮助

4

1 回答 1

3

使用 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
...

希望这可以帮助你

于 2013-05-09T19:13:51.497 回答