清除各物件欄位資料 (VB)

清除各物件欄位資料 (VB)

這迴圈是針對各物件來設定屬性 非常好用 分享給大家

For Each Control In Form1.Controls 'form1是該form的名稱
If TypeOf Control Is TextBox Then '物件為textbox
Control.Text = "" 'textbox物件的text設定為空白

'設為唯讀
        If TypeOf control Is TDBText Then 
            control.ReadOnly = False
        End If
        If TypeOf control Is TDBDate Then
            control.ReadOnly = False
        End If
        If TypeOf control Is TDBNumber Then
            control.ReadOnly = False
        End If
'enabled=true
        If TypeOf control Is DataCombo Then
            control.Enabled = True
        End If
         If TypeOf control Is Frame Then
            control.Enabled = True
        End If

End If
Next

 

'下面是鎖定SSTAB裡的TDBTEXT
    For Each control In SSTab1.Container
        If TypeOf control Is TextBox Then
            control.Locked = False
        End If
    Next

 


如有錯誤 歡迎指正