设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1693|回复: 5
打印 上一主题 下一主题

[模块/函数] 请教老和尚如何批量给每个文本框写同样的事件代码。

[复制链接]
跳转到指定楼层
1#
发表于 2015-4-20 22:18:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
比如文本框的鼠标键按下,事件过程全部是
If Button = 2 Then
   CommandBars("myCom").Controls(6).Enabled = False
   CommandBars("myCom").Controls(7).Enabled = False
   CommandBars("myCom").ShowPopup
End If

请教如何用最简单的方法给10几个文本框写上这几行代码。
有没有方法如
dim ctl as control
  for each ctl in me.controls
    if typeof ctl is textbox then
    ……写起上面的代码,让每个文本框鼠标右键按下后弹出菜单。
    end if
  next ctl
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2015-4-21 09:01:52 | 只看该作者
本帖最后由 roych 于 2015-4-21 09:03 编辑

dim ctl as control
  for each ctl in me.controls
    if typeof ctl is textbox then
            textbox.onclick="=函数名()"
    end if
  next ctl
把它放在窗体的加载事件中。具体可以参考以下帖子:
http://www.office-cn.net/thread-112360-1-1.html
3#
 楼主| 发表于 2015-4-21 19:17:29 | 只看该作者
roych 发表于 2015-4-21 09:01
dim ctl as control
  for each ctl in me.controls
    if typeof ctl is textbox then

老和尚,这招不灵啊,关键是onmousedown要判断鼠标右键的,就是那个if button=2不好搞,还有其它高招吗?
4#
发表于 2015-4-22 13:54:17 | 只看该作者
memphis240 发表于 2015-4-21 19:17
老和尚,这招不灵啊,关键是onmousedown要判断鼠标右键的,就是那个if button=2不好搞,还有其它高招吗?

试试用右键菜单吧。
http://jingyan.baidu.com/article/f25ef2540a83c8482c1b828a.html
顺便说一下,我不是老和尚,也不是喇嘛,我是有头发的,而且很茂密。

点击这里给我发消息

5#
发表于 2015-4-23 05:13:59 来自手机 | 只看该作者
用类 应可以的吧
6#
 楼主| 发表于 2015-4-30 10:27:46 | 只看该作者
roych 发表于 2015-4-22 13:54
试试用右键菜单吧。
http://jingyan.baidu.com/article/f25ef2540a83c8482c1b828a.html
顺便说一下,我 ...

好刀法。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-7 03:23 , Processed in 0.084618 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表