VBA:數據輸入組合框有效,但命令按鈕給出“無效的屬性值”錯誤 (VBA: Data entry into combobox works, but command button gives "Invalid property value" error)


問題描述

VBA:數據輸入組合框有效,但命令按鈕給出“無效的屬性值”錯誤 (VBA: Data entry into combobox works, but command button gives "Invalid property value" error)

我有一個帶有 3 個組合框和一個命令按鈕的用戶窗體,單擊該按鈕時,會將輸入的值放入工作表中。我將所有 3 個的 MatchRequired 設置為 True,這樣就無法輸入其他值。

我的問題是我可以毫無問題地通過每個組合框,因為沒有任何不准確之處。但是,當我單擊命令按鈕時,會出現 Invalid Property Value 錯誤。此外 ‑ 即使出現錯誤,條目仍會添加到工作表中。什麼給出了?

我正在從同一張紙上的不同列加載組合框選項。這是我的命令按鈕代碼:

Private Sub cmdAddClass_Click()

Dim RowCount As Long

RowCount = Worksheets("Sheet2").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet2").Range("A1")
    .Offset(RowCount, 0).Value = Me.cboGrade.Value
    .Offset(RowCount, 1).Value = Me.cboUnits.Value
    .Offset(RowCount, 2).Value = Me.cboQuarter.Value
End With

Me.cboGrade.Value = ""
Me.cboUnits.Value = ""
Me.cboQuarter.Value = ""
Me.cboGrade.SetFocus

End Sub

這裡是新的,非常感謝您的幫助。


參考解法

方法 1:

You issue is:

Me.cboGrade.Value = ""
'...
Me.cboGrade.SetFocus

You are setting cboGrade to blank, which is not a value in the combobox list. Therefore when you set the focus to cboGrade, the MatchRequired setting rejects it and issues the Invalid Property Value message. Note that this is not actually a VBA error, it's a message from the form control.

Try removing Me.cboGrade.SetFocus

(by joelhufford94chris neilsen)

參考文件

  1. VBA: Data entry into combobox works, but command button gives "Invalid property value" error (CC BY‑SA 2.5/3.0/4.0)

#Combobox #excel #vba






相關問題

tcl/tk 小部件組合框失去焦點 (tcl/tk widget combobox loses focus)

Flex Combobox 奇怪的問題 (Flex Combobox strange problem)

在組合框中對齊文本 (Align Text in Combobox)

如何同時綁定到 ComboBox 中的兩個不同的依賴屬性? (How do I bind to two different dependency properties in a ComboBox at the same time?)

在綁定到字典的組合框中設置所選項目 (Setting selected item in combobox bound to dictionary)

easyUI datagrid內部編輯組合框無法選擇默認值 (easyUI datagrid inner edit combobox cannot selected default value)

VBA:數據輸入組合框有效,但命令按鈕給出“無效的屬性值”錯誤 (VBA: Data entry into combobox works, but command button gives "Invalid property value" error)

vb.net - 組合框總是選擇第一個值 (vb.net - combo box always select the first value)

打開 ComboBox DropDown 時不要選擇文本輸入 (Do not select text input when ComboBox DropDown is opened)

如何使用相同的數據源設置多個組合框? (How can I set up multiple combo-boxes with the same data source?)

如何使用 QtreeView 在 QComboBox 中設置所選項目 (How to set selected item in QComboBox with QtreeView)

Tkinter 組合框 Python (Tkinter Combobox Python)







留言討論