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

Access窗体数据库访问报错:Forms![Meter Reading Date > Box].tbxCurrent命名括号无效

解决Access SQL中窗体控件引用的括号错误

你遇到的Invalid bracketing of name Forms![Meter Reading Date > Box].tbxCurrent]报错,根源主要有两个——窗体/控件的引用语法不规范,还有非法字符、HTML转义字符的干扰。下面是具体的修复步骤和修正后的SQL:

核心问题分析

  1. 非法字符混入窗体名:报错里的Meter Reading Date > Box多了个>,这明显是错误的。先打开窗体设计视图,查看属性表的“名称”字段,确认你的窗体实际名称是Meter Reading Date Box,没有多余的特殊字符。
  2. 控件引用格式不对:Access中引用带空格的窗体/控件时,需要用方括号分别包裹窗体和控件,正确格式是Forms![窗体名]![控件名],而不是只给窗体加方括号。
  3. HTML转义字符残留:你的SQL里出现了>,这是HTML的大于号转义字符,Access SQL不识别,要改成直接的>。

修正后的SQL语句

SELECT 
    0.3 AS CurrWaterRate, 
    Forms![Meter Reading Date Box]![tbxNewGasRate] AS CurrGasRate, 
    Forms![Meter Reading Date Box]![tbxNewElecRate] AS CurrElecRate, 
    4.65 AS BaseElec, 
    IIf([RV]=True,0,3) AS BaseGas, 
    IIf([RV]=True,0,9) AS Sewer, 
    IIf([RV]=True,0,13.35) AS Garbage, 
    [Current Month Utilities].*, 
    [Previous Month Utilities].*, 
    [Current Month Utilities]!KWHReading - [Previous Month Utilities]!KWHReading AS BillKWH, 
    [Current Month Utilities]!GasReading - [Previous Month Utilities]!GasReading AS BillGas, 
    [Current Month Utilities]!WaterReading - [Previous Month Utilities]!WaterReading AS BillWater, 
    [Customer Maintenance].*, 
    ([BillKWH]*[CurrElecRate]) AS DueKWH, 
    IIf([RV]=True,0, IIf([Electric]=True,0, IIf([BillGas]>10,6.5+([BillGas]-10)*[CurrGasRate],6.5))) AS DueGas, 
    IIf([RV]=True,0, IIf([BillWater]<3,8,([BillWater]-3)*0.3+8)) AS DueWat, 
    IIf([RV]=True,0, IIf([Electric]=True,0,3)) AS GasSurcharge, 
    (([DueWat]+[DueKWH]+[DueGas]+[GasSurcharge]+[Sewer]+[Garbage]+[BaseElec]+[BaseGas])*0.0825) AS Taxable, 
    [LotRent]+[TrailRent]+[DueWat]+[DueKWH]+[DueGas]+[GasSurcharge]+[Garbage]+[Sewer]+[Taxable]+[BaseElec]+[LateFee] AS TotalDue, 
    ([TotalDue]+[PastDue]-[Credit]) AS GrandTotal, 
    [FName] & " " & [LName] AS Name 
FROM 
    ([Customer Maintenance] INNER JOIN [Current Month Utilities] ON [Customer Maintenance].AccountNo=[Current Month Utilities].AccountNo) 
    INNER JOIN [Previous Month Utilities] ON [Customer Maintenance].AccountNo=[Previous Month Utilities].AccountNo;

关键修改点

  • 把forms![Meter Reading Date Box].tbxNewGasRate改成Forms![Meter Reading Date Box]![tbxNewGasRate](给控件也加上方括号,避免空格或特殊字符引发识别问题)
  • 将IIf([BillGas]&gt;10里的&gt;替换成Access能识别的>
  • 确保所有窗体/控件名称没有非法字符(比如报错里的>)

额外测试建议

如果还是报错,可以先单独测试控件引用是否有效:在查询里写SELECT Forms![Meter Reading Date Box]![tbxNewGasRate] AS Test,运行看是否能获取到控件值,逐步排查问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:51:52