Recordset.Update 数据库或对象是只读的 [英] Recordset.Update Database or Object is read-only
问题描述
不确定这是否适用于我想要的细节.该场景是文本框填充有表中的数据,用户编辑记录并单击按钮进行保存.
Not sure this is going to work in the specifics I intend. The scenario is the text boxes are populated with data from a table, and the user edits the records and clicks a button to save.
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
'不确定这是必要的.示例中引用了它,但不确定为什么?^'
'Not sure this is necessary. It was quoted in the example, but unsure why? ^'
!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,但在例程中未使用.
However, on clicking the save button, it errors stating that the Database or object is read only, and I'm unsure why. As far as I know it isn't open anywhere, nor should it get opened for any reason! Was hoping someone would be able to shed some light on the issue. The table has a primary key set, which is CompanyID however this isn't used in the routine.
推荐答案
Type 参数 dbOpenSnapShot
in:
The Type parameter dbOpenSnapShot
in:
Set rstEdit = CurrentDb.OpenRecordset(DataValues, dbOpenSnapshot)
使 rstEdit 作为只读记录集(或快照)打开.考虑改用 dbOpenDynaset
.
makes rstEdit open as a read-only recordset(or snapshot). Consider using dbOpenDynaset
instead.
这篇关于Recordset.Update 数据库或对象是只读的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!