For Each ctl In Controls

 米蟲 寫信:
目前小弟的寫法是
            Dim tmp_tb as control
            For Each tmp_tb In Me.Controls
                If TypeOf tmp_tb Is TextBox Then
                    tmp_tb.text = ""
                End If
            Next

 
 


1. 你的 tmp_tb 必須要先轉成 TextBox 才可以使用 tmp_tb.text = ""
2. 如果你的 TextBox 包在具有容器性質的控制項(例如 Table, Panel 這些)時,Me.Controls 會找不到 TextBox,你必須要使用遞迴的方式來處理 .


        Dim ctl As Control
        For Each ctl In Me.NavigationPanePanel1.Controls
            If TypeOf ctl Is TextBox Then
                ctl.Text = ""
            End If
        Next

 

 

 

此程序稍一修改便可达到更多的功能如锁定或解锁各栏位

Public Sub LockControls(frm As Form, blnSta As Boolean)
  Dim ctl As Control
  For Each ctl In frm.Controls
     If TypeOf ctl Is acTextBox Or TypeOf ctl Is acComboBox Then
      ctl.Enabled = blnSta
      DoEvents
     End If
  Next
End Sub

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值