2017-07-26 44 views
0

我已經查看了所有內容,甚至查看了文檔,並且無法找到看似簡單問題的答案。禁用表單上的特定控件

Dim ctl As Control 
For Each ctl In Me.Controls 
    If ctl.ControlType <> acComboBox Then 
     If ctl.Name <> "SrchVal" Then 
      ctl.Enabled = False 
     End If 
    End If 
Next ctl 

我在表單上有很多文本框控件用於數據輸入。他們都應該被鎖定(禁用),直到點擊某個按鈕,這個事件我會稍後處理。

但是,有幾個組合框控件和一個文本框控件我不想禁用,標題爲SrchVal

我知道Control對象沒有Enabled屬性,所以我該如何解決這個問題?

+0

CTL啓用=假 –

+0

我收到以下運行時錯誤:'Property Let過程沒有定義,屬性獲取過程未返回object' – Steven

+0

問題是什麼用你的代碼? –

回答

0

嘗試下面的代碼:

Dim ctl As Control 
For Each ctl In Me.Controls 
    Debug.Print TypeName(ctl) 
    If TypeName(ctl) <> "ComboBox" Then ' <-- check if control is not a Combo-Box 
     Debug.Print ctl.Name 
     If ctl.Name <> "SrchVal" Then 
      ctl.Enabled = False 
     End If 
    End If 
Next ctl 
+0

我仍然收到一條錯誤'ctl.Enabled = False' – Steven

+0

@Steven我剛剛測試過它,它運行良好,你可以分享其餘的user_form代碼? –

+0

這是窗體加載事件中唯一的代碼 – Steven

相關問題