gpt4 book ai didi

sql - Recordset.Update 数据库或对象是只读的

转载 作者:行者123 更新时间:2023-12-04 14:45:19 26 4
gpt4 key购买 nike

不确定这是否会在我打算的细节中起作用。场景是文本框填充了表中的数据,用户编辑记录并单击按钮进行保存。

Dim cdb As DAO.Database, rstEdit As DAO.Recordset
Set cdb = CurrentDb
DataValues = "SELECT * FROM Companies, Link_Table WHERE Companies.CompanyID = " & SelectedValue & ";"
Set rstEdit = CurrentDb.OpenRecordset(DataValues, dbOpenSnapshot)

With rstEdit
OldCompanyName = !CompanyName
OldCompanyDescription = !Description
OldFriendlyName = !FriendlyName
OldAddressLine1 = !AddressLine1
OldAddressLine2 = !AddressLine2
OldAddressLine3 = !AddressLine3
OldTown = !Town
OldPostcode = !AddressPostcode
OldCounty = !AddressCounty
OldMainTelephone = !MainTelephone
OldMainEmail = !MainEmail
OldWeb = !WebAddress

'不确定这是必要的。示例中引用了它,但不确定为什么? ^'
 !CompanyName = NewCompanyName
!Description = NewCompanyDescription
!FriendlyName = NewFriendlyName
!AddressLine1 = NewAddressLine1
!AddressLine2 = NewAddressLine2
!AddressLine3 = NewAddressLine3
!Town = NewTown
!AddressPostcode = NewPostcode
!AddressCounty = NewCounty
!MainTelephone = NewMainTelephone
!MainEmail = NewMainEmail
!WebAddress = NewWeb
.Update
End With

但是,在单击保存按钮时,它会出错,指出数据库或对象是只读的,我不确定为什么。据我所知,它没有在任何地方打开,也不应该出于任何原因打开!希望有人能够对这个问题有所了解。该表有一个主键集,即 CompanyID,但在例程中未使用。

最佳答案

类型参数 dbOpenSnapShot在:

Set rstEdit = CurrentDb.OpenRecordset(DataValues, dbOpenSnapshot)

使 rstEdit 作为只读记录集(或快照)打开。考虑使用 dbOpenDynaset反而。

关于sql - Recordset.Update 数据库或对象是只读的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20431018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com