You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MS Access VBA中Field.Properties.Append方法执行失败报错3219

Access字段DisplayControl属性设置报错3219的修复方案

问题根源

你在代码中先将字段Append到表的字段集合,之后再尝试给该字段添加DisplayControl属性——但DAO的Field对象一旦被添加到TableDef的Fields集合后就会变为只读状态,此时无法再添加新属性,这就是触发运行时错误3219的原因。

修复代码

调整字段创建、属性设置与追加的顺序,先设置属性,再将字段添加到表:

修改主过程中添加字段的循环段:

'add rest of the fields:
Do Until rst.EOF
    i = Me.subfFields.Form!cType
    If i = dbText Then
        Set fld = tbl.CreateField(Me.subfFields.Form!tName, i, Nz(Me.subfFields.Form!tSize, 255))
    Else
        Set fld = tbl.CreateField(Me.subfFields.Form!tName, i)
    End If
    ' 先设置DisplayControl属性,再将字段追加到表
    If Me.subfFields.Form!cControl = 111 Then
        SetDAOProperty fld, "DisplayControl", dbInteger, acComboBox
    End If
    tbl.Fields.Append fld
    rst.MoveNext
Loop

关键规则说明

DAO对象的编辑权限遵循:未被加入所属集合的对象处于可编辑状态,一旦通过Append方法加入集合,对象就会转为只读,无法再修改或新增属性。原代码的顺序正好违反了这个规则。

内容的提问来源于stack exchange,提问作者mits

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 20:05:29