我尝试在vba中引用子窗体控件的.Form属性时出现错误2467

时间:2016-11-16 21:26:34

标签: access-vba ms-access-2013

ETA:我跑过一位同事,他指出问题出在哪里。在底部回答。

我有一个父窗体设置,其中包含一些不可见的子窗体控件。每个子窗体控件在设计时链接到不同的子窗体,然后我在父窗口上有一些代码,它们将每个子窗体控件飞到相关位置,并使用户可以看到它。

这是执行此操作的一段代码:

    Set Me.childRegion_MVC.Form.Recordset = rs2
    Me.childRegion_MVC.Form.cmdClearAll.Enabled = intCount > 0
    Me.childRegion_MVC.Form.cmdSetAll.Enabled = intCount < rs.RecordCount

    'Position the subform under the relevant combo box  <===== requires tailoring
    Me.childRegion_MVC.Left = Me.cboRegion.Left
    Me.childRegion_MVC.Top = Me.cboRegion.Top + Me.cboRegion.Height
    Me.childRegion_MVC.Width = Me.cboRegion.Width
    Me.childRegion_MVC.Height = cintTWIPS_CM * 4.5 ' height needs to be set in twips

    Call Me.childRegion_MVC.Form.InitRegion   ' Ensures the subform's recordset is open and binds the subform controls
    Me.childRegion_MVC.Visible = True
    Me.childRegion_MVC.SetFocus

这是另一个:

    Set Me.childBusiness_MVC.Form.Recordset = rs2
    Me.childBusiness_MVC.Form.cmdClearAll.Enabled = intCount > 0
    Me.childBusiness_MVC.Form.cmdSetAll.Enabled = intCount < rs.RecordCount

    'Position the subform under the relevant combo box  <===== requires tailoring
    Me.childBusiness_MVC.Left = Me.cboBusiness.Left
    Me.childBusiness_MVC.Top = Me.cboBusiness.Top + Me.cboBusiness.Height
    Me.childBusiness_MVC.Width = Me.cboBusiness.Width
    Me.childBusiness_MVC.Height = cintTWIPS_CM * 4.5 ' height needs to be set in twips

    Call Me.childBusiness_MVC.Form.InitBusiness   ' Ensures the subform's recordset is open and bind the subform controls
    Me.childBusiness_MVC.Visible = True
    Me.childBusiness_MVC.SetFocus

我的问题是第一个代码块在运行时的第一行抛出错误2467(“您输入的表达式是指关闭或不存在的对象。”)在我设置的第一行Recordset使用预备份记录集对象(rs2)),而第二个块不使用。

查看调试窗口,第一种情况下不存在子控件的.Form属性;而它在第二个 - 所以这是错误的直接原因,但我无法弄清楚为什么形式对象不适用于第一个例子:

  • 在两种情况下都以相同的方式准备/打开了rs2
  • 两个子表单控件(childRegion_MVCchildBusiness_MVC)在设计模式下设置了相同的属性
  • 数据库中存在两个源对象(subfrmRegion_MVCsubfrmBusiness_MVC
  • 我已经对数据库进行了压缩/修复和反编译,以清除可能存在的任何腐败问题。

但是当我尝试使用它时,childRegion_MVC仍然会破坏我的形式。

有谁可以建议这里可能会发生什么?我完全被难倒了。

+++解决方案+++

事实证明问题是有问题的子表单上的记录源损坏。

这导致子窗体在作为父窗体启动的一部分打开时具有空记录集,因此它立即关闭 - 这意味着当我的代码稍后尝试引用它时没有可用的窗体。

0 个答案:

没有答案