我正在創建課程計劃的項目。我正在使用Access。所以,假設我已經創建了一些課程表。現在我想使用與表格數據綁定的組合框。我設法做到了這一點。但我的問題是例如。如果我在第一個組合框中選擇了一個課程,我希望在第二個組合框中禁用該課程,以便我無法選擇它。對於每個組合框等(對於六個組合框,請說這樣做)動態填充和更新組合框中的項目
我有這個代碼。但是,我的代碼的問題是,每當我在第三個組合框中選擇了某些內容時,我的數據將從上面的組合框中刪除。
Private Sub cboMonday_AfterUpdate()
Me.cboTuesday.RowSource = "SELECT CourseName FROM" & _
" tblCourses "
Me.cboWednesday.RowSource = "SELECT CourseName FROM" & _
" tblCourses "
MsgBox ("After Monday= ")
Dim i As Integer
For i = 0 To Me.cboMonday.ListCount - 1
If i <> Me.cboMonday.Value - 1 Then
Me.cboTuesday.AddItem (Me.cboMonday.ItemData(i))
End If
Next
Me.cboTuesday = Me.cboTuesday.ItemData(0)
For i = 0 To Me.cboMonday.ListCount - 1
If i <> Me.cboMonday.Value - 1 Then
Me.cboWednesday.AddItem (Me.cboMonday.ItemData(i))
End If
Next
Me.cboWednesday = Me.cboWednesday.ItemData(1)
End Sub
Private Sub cboTuesday_AfterUpdate()
Me.cboWednesday.RowSource = "SELECT CourseName FROM" & _
" tblCourses "
Dim i As Integer
MsgBox ("After Tuesday= ")
For i = 0 To Me.cboMonday.ListCount - 1
If i <> Me.cboMonday.Value - 1 And i <> Me.cboTuesday.Value - 1 Then
Me.cboWednesday.AddItem (Me.cboMonday.ItemData(i))
End If
Next
Me.cboWednesday = Me.cboWednesday.ItemData(0)
End Sub
我該如何拒絕帶有警告的選擇。 – Skofiar
'BeforeUpdate'事件的參數爲'Cancel'。如果將其設置爲「True」,則不會接受選定的值。檢查是否選擇了錯誤的值,彈出消息,設置'Cancel = true'並退出sub –