複製從:https://softwareengineering.stackexchange.com/questions/158330/cascading-comboboxes級聯組合框
行,所以我有一個表格,在訪問2010中,用1個文本框和3個組合框(1啓用& 2關閉)。
第一個ComboBox不綁定到數據源,但是對其他2個ComboBox是主觀的。所以我處理了第一個Combobox的Click事件,然後使其他2啓用,並預先加載第二個ComboBox與一個基於第一個ComboBox值動態構建的自定義RowSource SQL腳本。
這一切都適用於新信息,但當我通過窗體回顧信息時,它回到控件上的新模式。
問題: 我需要處理哪些事件來檢查當前表單數據是否包含控件的控件源的數據?
如我所表達出來的邏輯(其C & VB的混合體,我知道,但應該得到的PT acrossed):
DataSet ds = Form.RowSet
if (ds = Null) then
cbo2.enabled = false
cbo3.enabled = false
else
cbo2.rowsource = "select id, nm from table"
cbo2.value = ds(3)
cbo3.value = ds(4)
end if
... do some other logic ...
更新邏輯 - 儘管如此問題,斜面抓了RECORDSTATUS出於某種原因(給3251運行時錯誤)
Private Sub Form_Current()
Dim boolnm As Boolean: boolnm = (IsNull(txtName.Value) Or IsEmpty(txtName.Value))
Dim booltype As Boolean: booltype = IsNull(cboType.Value)
Dim boolfamily As Boolean: boolfamily = IsNull(cboType.Value)
Dim boolsize As Boolean: boolsize = IsNull(cboType.Value)
Dim rs As DAO.Recordset: Set rs = Me.Recordset
MsgBox rs.AbsolutePosition
' If rs.RecordStatus = dbRecordNew Then
' MsgBox "New Record being inserted, but not committed yet!", vbOKOnly
' Else
' MsgBox rs(0).Name & " - " & rs(0).Value & vbCrLf & _
' rs(1).Name & " - " & rs(1).Value & vbCrLf & _
' rs(2).Name & " - " & rs(2).Value & vbCrLf & _
' rs(3).Name & " - " & rs(3).Value
' End If
'MsgBox "Name: " & CStr(boolnm) & vbCrLf & _
"Type: " & CStr(booltype) & vbCrLf & _
"Family: " & CStr(boolfamily) & vbCrLf & _
"Size: " & CStr(boolsize), vbOKOnly
End Sub
'如果Me.NewRecord Then',則不需要記錄集。 – Fionnuala 2012-07-26 15:44:10