Application.CurrentObjectType 属性 (Access)
将 CurrentObjectType 属性与 Application 对象结合使用,确定活动数据库对象的类型 (表、查询、窗体、报表、宏、模块、服务器视图、数据库关系图或存储过程) 。 活动数据库对象是具有焦点或正在运行代码的对象。 只读的 AcObjectType 。
语法
表达式。CurrentObjectType
expression:表示 Application 对象的变量。
备注
下列条件确定将哪一对象视为活动对象:
如果活动对象是属性表、 命令栏、 菜单、 调色板或字段列表中的某个对象,则 CurrentObjectType 属性返回基础对象的类型。
如果活动对象是弹出式窗体, CurrentObjectType 属性是指该弹出式窗体本身,无法打开该表单。
如果活动对象是数据库窗口, CurrentObjectType 属性返回数据库窗口中的选定项。
如果未选定对象,则 CurrentObjectType 属性返回 True 。
如果当前状态不明确 (活动对象不是表、查询、窗体、报表、宏或模块) ,例如,如果对话框具有焦点, 则 CurrentObjectType 属性返回 True。
将此属性与 SysCmd 方法结合使用,以确定活动对象及其状态 (例如,如果对象已打开、新建或已更改,但未) 保存。
示例
下面的示例使用 SysCmd 函数 CurrentObjectType 和 模糊 属性以确定活动对象是产品窗体,如果该窗体已打开,并且已被更改但没有保存。 如果这些情况属实,该窗体是否保存并关闭。
Public Sub CheckProducts()
Dim intState As Integer
Dim intCurrentType As Integer
Dim strCurrentName As String
intCurrentType = Application.CurrentObjectType
strCurrentName = Application.CurrentObjectName
If intCurrentType = acForm And strCurrentName = "Products" Then
intState = SysCmd(acSysCmdGetObjectState, intCurrentType, _
strCurrentName)
' Products form changed but not saved.
If intState = acObjStateDirty + acObjStateOpen Then
' Close Products form and save changes.
DoCmd.Close intCurrentType, strCurrentName, acSaveYes
End If
End If
End Sub
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。