米蟲 寫信:
目前小弟的寫法是
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