Ralf Eisenreich

SQLBlog.DE | ..things to remember

April 8th, 2006

MS Access: Multiselect in Queries

IT, VBA, by Ralf.

In MS Access verwendet man in den Benutzerschnittstellen gern Listen mit Multiselect-Funktion, um dem Anwender flexiblere Auswahlmöglichkeiten zu bieten.

In Queries ist es jedoch etwas schwierig diese Optionen abzufragen. Folgende VBA-Funktion schafft da Abhilfe:

Function InMultiSelect(frms, ctrl As String, col As Integer, data As Variant, ParamArray OtherArgs()) As Boolean
'Checks whether a Variant (data or OtherArgs) is included in the specified column (col) of a ListBox (ctrl)
'in a certain Form (frms)
On Error GoTo Error_InMultiSelect
Dim varItm As Variant
Dim index As Integer
Dim ctl As Control
Dim frm As Form
Set frm = Forms(frms)
Set ctl = frm.Controls(ctrl)
InMultiSelect = False
For Each varItm In ctl.ItemsSelected
If InMultiSelect = True Then Exit For
If CStr(data) = CStr(ctl.Column(col, varItm)) Then InMultiSelect = True
For index = LBound(OtherArgs) To UBound(OtherArgs)
If InMultiSelect = True Then Exit For
If CStr(OtherArgs(index)) = CStr(ctl.Column(col, varItm)) Then InMultiSelect = True
Next index
Next varItm
Exit Function
Error_InMultiSelect:
InMultiSelect = False
Exit Function
End Function

In den Abfragen (Queries) selbst wird diese Funktion dann beispielsweise so aufgerufen:


SELECT *
FROM [tblTabelle]
WHERE InMultiSelect("[frmFormMitMultiSelectAuswahl]","[lstListeMitMultiSelectAuswahl]",0,[tblTabelle].[Spalte]))<>False);

Back Top

Responses to “MS Access: Multiselect in Queries”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Security Code: