我一直致力於爲數據庫組織分配的閱讀器的文檔資源,以便在我的辦公室輕鬆訪問和查看。聯合查詢級聯組合框查詢
我已經採取了從here級聯組合框框架,我希望能夠讓審閱者和分配者根據標準在子表單中篩選文檔。這個問題在很大程度上是由於我的組織讓我有一個分支線性關係樹,而不是一個直線性關係樹。這裏有很多有用的提示,但我似乎無法得到正確的組合,因此解決了我的障礙。
關係樹如下紙張類型> SubCommittee> Session> Papers。我已經解決了這個問題,因爲我正在審覈來自一種來源(國際資源)的論文,該論文有兩種論文類型(工作和非正式),並且有幾個小組委員會(我的辦公室只對兩個委員會感興趣)。
級聯工作正常,子窗體最初以正確的方式從查詢中填充,但是當選擇選項時,查詢無法與查找值相匹配。
認定爲qrylstpapers查詢包含以下字段:
PaperTypeName, SubCommitteeName, SessionNumber, PaperNumber, Title, Subject, Origin.
這些字段從表PaperType,小組委員會會議拉昇,論文
我有兩個疑問,一個用於工作,一個用於非正式的類型。我有第三個聯盟查詢來結合這兩個。
我認爲,從聯合查詢進行查詢會使它更容易,並且當它填充子窗體時,排序不起作用。
我正在使用VBA的聯合查詢的查詢類型命令如下:
Private Sub FilterPaperList()
Dim strRS As String
strRS = "SELECT qrylstpapers.Title, qrylstpapers.PaperTypeName FROM qrylstpapers"
If Not IsNull(Me.cboPaperNumberAssign) Then
strRS = strRS & " WHERE PaperNumber = " & Me.cboPaperNumberAssign
ElseIf Not IsNull(Me.cboSessionAssign) Then
strRS = strRS & " WHERE SessionNumber = " & Me.cboSessionAssign
ElseIf Not IsNull(Me.cboSubCommitteeAssign) Then
strRS = strRS & " WHERE SubCommitteeName = " & Me.cboSubCommitteeAssign
ElseIf Not IsNull(Me.cboPaperTypeAssign) Then
strRS = strRS & " WHERE PaperTypeName = " & Me.cboPaperTypeAssign
End If
strRS = strRS & " ORDER BY qrylstpapers.Title;"
Me.lstPapers.RowSource = strRS
Me.lstPapers.Requery
End Sub
有一件事我沒有嘗試那種工作是指定「Me.cboPapertypeAssign.Column(1) 「它會彈出一個對話框窗口詢問輸入,緊接着papertypename」WP「或」INF「會給我適當的排序。
任何想法,見解,和/或一般的批評將不勝感激。即使這是關係的重組。
編輯
Option Compare Database
Option Explicit
Private Sub cboAgency_AfterUpdate()
' Set the Mode combo box to be limited by the selected Agency
Me.cboMode.RowSource = "SELECT tblMode.ModeID, tblMode.ModeName FROM tblMode " & _
" WHERE AgencyID = " & Nz(Me.cboAgency) & _
" ORDER BY ModeName"
Me.cboMode = Null
EnableControls
End Sub
Private Sub cboMode_AfterUpdate()
' Set the Branch combo box to be limited by the selected Mode
Me.cboBranch.RowSource = "SELECT tblBranch.BranchID, tblBranch.BranchName FROM tblBranch " & _
" WHERE ModeID = " & Nz(Me.cboMode) & _
" ORDER BY BranchName"
Me.cboBranch = Null
EnableControls
End Sub
Private Sub cboBranch_AfterUpdate()
' Set the Office combo box to be limited by the selected Branch
Me.cboOffice.RowSource = "SELECT tblOffice.OfficeID, tblOffice.OfficeNumber FROM tblOffice " & _
" WHERE BranchID = " & Nz(Me.cboBranch) & _
" ORDER BY OfficeNumber"
Me.cboOffice = Null
EnableControls
End Sub
Private Sub cboOffice_AfterUpdate()
' Set the Reviewer combo box to be limited by the selected Office
Me.cboReviewer.RowSource = "SELECT tblReviewers.ReviewerID, tblReviewers.LastName FROM tblReviewers " & _
" WHERE OfficeID = " & Nz(Me.cboOffice) & _
" ORDER BY LastName"
Me.cboReviewer = Null
EnableControls
End Sub
Private Sub cboPaperTypeAssign_AfterUpdate()
'Enable the SubCommittee Combo Box
If Me.cboPaperTypeAssign.Column(1) = "WP" Then
Me.cboSubCommitteeAssign.RowSource = "SELECT tblUNWPSubCommittee.SubCommitteeID, tblUNWPSubCommittee.SubCommitteeName From tblUNWPSubCommittee " & _
" Where PaperTypeID = " & Nz(Me.cboPaperTypeAssign) & _
" ORDER BY SubCommitteeName"
Me.cboSubCommitteeAssign = Null
ElseIf Me.cboPaperTypeAssign.Column(1) = "INF" Then
Me.cboSubCommitteeAssign.RowSource = "SELECT tblUNINFSubCommittee.SubCommitteeID, tblUNINFSubCommittee.SubCommitteeName From tblUNINFSubCommittee " & _
" Where PaperTypeID = " & Nz(Me.cboPaperTypeAssign) & _
" ORDER BY SubCommitteeName"
Me.cboSubCommitteeAssign = Null
End If
EnableControls
FilterPaperList
End Sub
Private Sub cboSubCommitteeAssign_AfterUpdate()
'Enable the Session Combo Box
If Me.cboSubCommitteeAssign.Column(1) = "GHS" And Me.cboPaperTypeAssign.Column(1) = "INF" Then
Me.cboSessionAssign.RowSource = "SELECT tblUNINFSessions.SessionID, tblUNINFSessions.SessionNumber From tblUNINFSessions " & _
" Where SubCommitteeID = " & Nz(Me.cboSubCommitteeAssign) & _
" ORDER BY SessionNumber"
Me.cboSessionAssign = Null
ElseIf Me.cboSubCommitteeAssign.Column(1) = "TDG" And Me.cboPaperTypeAssign.Column(1) = "INF" Then
Me.cboSessionAssign.RowSource = "SELECT tblUNINFSessions.SessionID, tblUNINFSessions.SessionNumber From tblUNINFSessions " & _
" Where SubCommitteeID = " & Nz(Me.cboSubCommitteeAssign) & _
" ORDER BY SessionNumber"
Me.cboSessionAssign = Null
ElseIf Me.cboSubCommitteeAssign.Column(1) = "GHS" And Me.cboPaperTypeAssign.Column(1) = "WP" Then
Me.cboSessionAssign.RowSource = "SELECT tblUNWPSessions.SessionID, tblUNWPSessions.SessionNumber From tblUNWPSessions " & _
" Where SubCommitteeID = " & Nz(Me.cboSubCommitteeAssign) & _
" ORDER BY SessionNumber"
Me.cboSessionAssign = Null
ElseIf Me.cboSubCommitteeAssign.Column(1) = "TDG" And Me.cboPaperTypeAssign.Column(1) = "WP" Then
Me.cboSessionAssign.RowSource = "SELECT tblUNWPSessions.SessionID, tblUNWPSessions.SessionNumber From tblUNWPSessions " & _
" Where SubCommitteeID = " & Nz(Me.cboSubCommitteeAssign) & _
" ORDER BY SessionNumber"
Me.cboSessionAssign = Null
End If
EnableControls
FilterPaperList
End Sub
Private Sub cboSessionAssign_AfterUpdate()
'Enable the Paper Number Combo Box
If Me.cboSubCommitteeAssign.Column(1) = "GHS" And Me.cboPaperTypeAssign.Column(1) = "INF" Then
Me.cboPaperNumberAssign.RowSource = "Select tblUNINFPapers.ID, tblUNINFpapers.PaperNumber From tblUNINFPapers " & _
" Where SessionID = " & Nz(Me.cboSessionAssign) & _
" Order by PaperNumber"
ElseIf Me.cboSubCommitteeAssign.Column(1) = "TDG" And Me.cboPaperTypeAssign.Column(1) = "INF" Then
Me.cboPaperNumberAssign.RowSource = "Select tblUNINFPapers.ID, tblUNINFpapers.PaperNumber From tblUNINFPapers " & _
" Where SessionID = " & Nz(Me.cboSessionAssign) & _
" Order by PaperNumber"
ElseIf Me.cboSubCommitteeAssign.Column(1) = "GHS" And Me.cboPaperTypeAssign.Column(1) = "WP" Then
Me.cboPaperNumberAssign.RowSource = "Select tblUNWPPapers.ID, tblUNWPPapers.PaperNumber From tblUNWPPapers " & _
" Where SessionID = " & Nz(Me.cboSessionAssign) & _
" Order by PaperNumber"
ElseIf Me.cboSubCommitteeAssign.Column(1) = "TDG" And Me.cboPaperTypeAssign.Column(1) = "WP" Then
Me.cboPaperNumberAssign.RowSource = "Select tblUNWPPapers.ID, tblUNWPPapers.PaperNumber From tblUNWPPapers " & _
" Where SessionID = " & Nz(Me.cboSessionAssign) & _
" Order by PaperNumber"
End If
EnableControls
FilterPaperList
End Sub
Private Sub cboPaperNumberAssign_AfterUpdate()
' Filter the list of papers based on the selection(s)
FilterPaperList
End Sub
Private Sub FilterPaperList()
Dim strRS As String
' Filter the list box appropriateley based on the combo box selection(s)
strRS = "SELECT qrylstpapers.Title, qrylstpapers.PaperTypeName FROM qrylstpapers"
If Not IsNull(Me.cboPaperNumberAssign) Then
strRS = strRS & " WHERE PaperNumber = " & Me.cboPaperNumberAssign
ElseIf Not IsNull(Me.cboSessionAssign) Then
strRS = strRS & " WHERE SessionNumber = " & Me.cboSessionAssign
ElseIf Not IsNull(Me.cboSubCommitteeAssign) Then
strRS = strRS & " WHERE SubCommitteeName = " & Me.cboSubCommitteeAssign
ElseIf Not IsNull(Me.cboPaperTypeAssign) Then
strRS = strRS & " WHERE PaperTypeName = " & Me.cboPaperTypeAssign
End If
strRS = strRS & " ORDER BY qrylstpapers.Title;"
Me.lstPapers.RowSource = strRS
Me.lstPapers.Requery
End Sub
Private Sub EnableControls()
' Clear the Reviewer combo boxes
If IsNull(Me.cboAgency) Then
Me.cboMode = Null
End If
If IsNull(Me.cboMode) Then
Me.cboBranch = Null
End If
If IsNull(Me.cboBranch) Then
Me.cboOffice = Null
End If
If IsNull(Me.cboOffice) Then
Me.cboReviewer = Null
End If
' Clear the PaperAssign combo boxes
If IsNull(Me.cboPaperTypeAssign) Then
Me.cboSubCommitteeAssign = Null
End If
If IsNull(Me.cboSubCommitteeAssign) Then
Me.cboSessionAssign = Null
End If
If IsNull(Me.cboSessionAssign) Then
Me.cboPaperNumberAssign = Null
End If
' Enable or disable Reviewer combo boxes based on whether the combo box preceeding it has a value.
Me.cboMode.Enabled = (Not IsNull(Me.cboAgency))
Me.cboBranch.Enabled = (Not IsNull(Me.cboMode))
Me.cboOffice.Enabled = (Not IsNull(Me.cboBranch))
Me.cboReviewer.Enabled = (Not IsNull(Me.cboOffice))
' Enable or disable PaperAssign combo boxes based on whether the combo box preceeding it has a value.
Me.cboSubCommitteeAssign.Enabled = (Not IsNull(Me.cboPaperTypeAssign))
Me.cboSessionAssign.Enabled = (Not IsNull(Me.cboSubCommitteeAssign))
Me.cboPaperNumberAssign.Enabled = (Not IsNull(Me.cboSessionAssign))
End Sub
Private Sub Form_Load()
EnableControls
FilterPaperList
End Sub
我希望我不必發佈所有東西,儘管它很長,但是你花時間編寫/修改的代碼並不能解決我的問題。所以,我已將所有內容添加到了原始帖子中。 –