确定子窗体/子报表是否在MS Access中加载了窗体或报表 [英] Determine if Subform/Subreport Has a Form or a Report Loaded in MS Access

查看:207
本文介绍了确定子窗体/子报表是否在MS Access中加载了窗体或报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Access 2010数据库的表单上显示了一个子表单/子报表"控件,并使用它来显示表单"和报表".我有一些事件处理程序,我需要在其中了解是否当前将报表加载到了Subform/Subreport控件中,或者它是否是已加载的Form.我尝试了以下所有方法都无济于事.

I have a Subform/Subreport control displayed on a Form in an Access 2010 database, and I use it to display both Forms and Reports. I have a few event handlers in which I need to know whether a Report is currently loaded into the Subform/Subreport control, or if it's a Form that's loaded. I have tried all of the following to no avail.

以下任何一种情况

If IsEmpty(NavigationSubform.Form) Then '...
If IsNull(NavigationSubform.Form) Then '...
If IsOject(NavigationSubform.Form) Then '...
If NavigationSubform.Form Is Nothing Then '...
If NavigationSubform.Form Is Null Then '...
If Nz(NavigationSubform.Form) Then '...
If (Not NavigationSubform.Form) = -1 Then '... This is a trick I use to check for uninitialized arrays

结果

运行时错误"2467":

Run-time error '2467':

您输入的表达式是指已关闭或不存在的对象.

The expression you entered refers to an object that is closed or doesn't exist.

是否可以通过某种方式检查子表单/子报表控件当前是否已加载表单或报表,而没有故意导致错误?

Is there some way that I can check whether a Subform/Subreport control currently has a Form or Report loaded without intentionally causing an error?

推荐答案

我不认为有一种方法可以可靠地执行检查而不会出现错误陷阱,因此您可能希望将代码包装在Public Function中,然后将其放入常规的VBA模块中:

I don't believe that there is a way to reliably perform the check without error trapping, so you may want to wrap the code in a Public Function and put it into a regular VBA Module:

Public Function CheckSubformControlContents(ctl As SubForm) As String
Dim obj As Object, rtn As String
rtn = "None"
On Error Resume Next
Set obj = ctl.Form
If Err.Number = 0 Then
    rtn = "Form"
Else
    On Error Resume Next
    Set obj = ctl.Report
    If Err.Number = 0 Then
        rtn = "Report"
    End If
End If
Set obj = Nothing
On Error GoTo 0
CheckSubformControlContents = rtn
End Function

然后您的表单代码可以简单地调用CheckSubformControlContents(Me.NavigationSubform).

Then your form code can simply call CheckSubformControlContents(Me.NavigationSubform).

这篇关于确定子窗体/子报表是否在MS Access中加载了窗体或报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆