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

MS Access文本框动态设置控件源出现#Name?错误问题求助

Access文本框动态设置控件源报错问题

这是我此前相关提问的后续,我基本实现了预期功能(仍在确认是否选用了最优方案),目前遇到了文本框动态设置控件源的相关问题。

我通过VBA代码设置控件源时,除非将对应表添加到窗体的Record Source中,否则会触发*#Name?*错误。但我处理的数据量极大,将所有表都添加到记录源会触发"Too many fields defined"错误。

我使用如下代码设置控件源:

Set rst = db.OpenRecordset("feedersTBL", dbOpenDynaset)
rst.MoveFirst
    Do While Not rst.EOF
        If Me!subID = rst!stationID Then
        i = i + 1
        Me.Controls("Feeder" & i).Visible = True
        
        Set rst2 = db.OpenRecordset("feedersLoadingTBL", dbOpenDynaset)
        
        '绑定文本框
        For Each fld In rst2.Fields
            If fld.Name = rst!feederId Then
                Me.Controls("Feeder" & i).ControlSource = rst!feederId
                Debug.Print Me.Controls("Feeder" & i).ControlSource
                Exit For
            End If
        Next
     rst.MoveNext
 Loop

注:feedersLoadingTBL表有超过400列,我已将其拆分为4个表。


编辑补充

我按照@June7的建议改用DLookUp函数,针对Date这类静态字段可以正常运行,但动态字段的代码始终无法生效,新代码如下:

[其他代码]
   ⋮
   Me.Controls("Feeder" & i).ControlSource = "=DLookup(""[fld.Name]"", ""[feedersLoadingTBL]"", ""[time] =1"")"
   ⋮
[其他代码]

其中[fld.Name]是循环中会变动的部分。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 14:00:05