問題描述
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 joelhufford94、chris neilsen)