簡體   English   中英

Access 2010中的多選列表框

[英]Multiselect listbox in Access 2010

因此,我有此搜索表單,可根據設計者類型過濾項目。 設計人員可以是內部,外部或組合的。 最初是使用組合框完成的。 我被要求這樣做,以便用戶可以按多個選項進行過濾,因此我將其更改為一個列表框,以使用multiselect選項。

列表框工作正常,直到我將multiselct選項設置為除無選項以外的任何選項。 然后,將返回所有項目,而不是所選擇的項目。

我對Access或VBA的經驗不是很豐富,因此將不勝感激。 以下是本節的代碼。

Private Sub toDesignerExcel_Click()
Dim db As DAO.Database
Dim rs1, rs2 As DAO.Recordset
Dim sSQL1, sSQL2, SourceExcel, FileName, Path As String


Set db = CurrentDb


sSQL1 = "Select ExcelPath from tblBackendFiles where Setting = 'ExcelDesignerParameters'"
sSQL2 = "Select Setting from tblBackendFiles where Code = 'SourceExcel'"

Set rs1 = db.OpenRecordset(sSQL1)
FileName = Nz(rs1!ExcelPath, "")

Set rs2 = db.OpenRecordset(sSQL2)
SourceExcel = Nz(rs2!Setting, "")

Path = SourceExcel + "\" + FileName

rs1.Close
rs2.Close
db.Close
Set rs1 = Nothing
Set rs2 = Nothing
Set db = Nothing

Shell "C:\WINDOWS\explorer.exe """ & Path, vbNormalFocus
End Sub

編輯:而且,

If Forms(formName).txtDesigner <> "" And Not IsNull(Forms(formName).txtDesigner) Then
   If selEngConditions <> "" Then
        selEngConditions = selEngConditions & " AND "
   End If
        selEngConditions = selEngConditions & "[Activity].[GWPDesigner] = '" &    Forms(formName).txtDesigner & "'"
End If

我會做這樣的事情:

Private Sub toDesignerExcel_Click()
Dim db As DAO.Database
Dim rs1, rs2 As DAO.Recordset
Dim sSQL1, sSQL2, SourceExcel, FileName, Path As String

Set db = CurrentDb
sSQL1 = "Select ExcelPath from tblBackendFiles where Setting = 'ExcelDesignerParameters' And [Tblbackendfiles] = '"
sSQL2 = "Select Setting from tblBackendFiles where Code = 'SourceExcel'  And [Tblbackendfiles] = '"

For Each it In Me.ListBoxName.ItemsSelected

    Set rs1 = db.OpenRecordset(sSQL1 & it & "'")
    FileName = Nz(rs1!ExcelPath, "")

    Set rs2 = db.OpenRecordset(sSQL2 & it & "'")
    SourceExcel = Nz(rs2!Setting, "")
    Path = SourceExcel + "\" + FileName

    Shell "C:\WINDOWS\explorer.exe """ & Path, vbNormalFocus

    rs1.Close
    rs2.Close
    Set rs1 = Nothing
    Set rs2 = Nothing

Next it

db.Close
Set db = Nothing

End Sub

您基本上在其中迭代列表框中所有選定項目的位置。 這將從查詢的where子句中的列表框中添加每個選定的項目。

您也可以嘗試連接所有值並將查詢更改為:

And [Tblbackendfiles] In (" & comma_separated_list & ")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM