列出MS Access表单的控件及其事件 [英] List an MS Access form's controls with their events

查看:55
本文介绍了列出MS Access表单的控件及其事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个庞大的Access表单,其中包含数百个控件,并且都带有一些事件.其中之一是引发有关验证或更新后事件"的错误消息.没有控件名称,仅此而已.

I have a humongous Access form with hundreds of controls, all with some events. One of them is throwing an error crying about "Validation or After Update event". No control name, nothing more to go by.

因此,我想列出所有具有其所有验证规则和所有事件的表单(并非所有表单都是"[Event procedure]",有些是自定义函数调用).

So I figured I'd list all the forms with all their validation rules and all their events (not all of them are "[Event procedure]", some are custom function calls).

有什么方法可以获取控件的事件列表吗?

Is there any way to get a list of a control's events?

到目前为止,我的代码:

My code so far:

Sub ListAllControlsAndTheirEvents(FormToCheck As Form)
 Dim ctrlCurrent As Control
 For Each ctrlCurrent In FormToCheck.Controls
   Debug.Print "Name: " & ctrlCurrent.Name
   On Error Resume Next
     Debug.Print "Validation: " & ctrlCurrent.ValidationRule 'Not all controls have a ValidationRule property.
   On Error GoTo 0
   For Each eventCurrent In ctrlCurrent.events 'this thing doesn't exist :(
     Debug.Print "Event: " & eventCurrent.Name & "; value: " & eventCurrent.whatever
   Next
 Next
End Sub

那么,有没有办法实现这一部分?

For Each eventCurrent In ctrlCurrent.events 'this thing doesn't exist :(
  Debug.Print "Event: " & eventCurrent.Name & "; value: " & eventCurrent.whatever
Next

浏览代码模块不会给我自定义函数事件调用,只是[Event Procedure]代码.

Digging through the code module won't give me the custom function event calls, just the [Event Procedure] codes.

推荐答案

您可以使用typename来确定控件的类型,然后进行类似 if typename(x)="CommanButton"的设置,然后设置cb = x,然后循环属性,对于以On开头的属性名称,如果有一个[Event Procedure],您知道有一个事件,那么您也可以将搜索范围缩小到x_Click

You could use typename to determine the type of control, then set so something like if typename(x) ="CommanButton" then set cb=x, then loop the properties, for property names beginning with On, then if there is an [Event Procedure] you know there's an event, also you can then narrow down your search to x_Click

这篇关于列出MS Access表单的控件及其事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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