Zone de liste multi selection comme critère requete

Le
Marc
Bonjour à tous

je recherche svp une aide , un module concernant l'utilisation comme
critères pour une requête les entrées choisies dans une zone multi
sélections ?

Merci Bcp M
Vidéos High-Tech et Jeu Vidéo
Téléchargements
Vos réponses
Gagnez chaque mois un abonnement Premium avec GNT : Inscrivez-vous !
Trier par : date / pertinence
Thierry
Le #22661661
?Bonjour,
J'ai trouvé ce qui suit sur le site
http://www.vb123.com/kb/index.html?related_topics.htm

Bon courage
======================================================================
Ken Getz

You've given your users a multi-select box and they've selected the items
they want. This code turns their selection into a SQL Where clause so you
can retrieve the items they've asked for. The IN keyword works nicely here
because it matches all the items in a list (such as IN("item1", "item2", . .
.)). The code creates the necessary input by walking the ItemsSelected
collection of the list box, tacking every element in the property onto a
string, and putting quotes around it:

Function BuildIn(lstItems As Control, _

strFieldName As String) As String

Dim varItem As Variant

Dim strOut As String

Const conQuote = """"



If lstItems.ItemsSelected.Count = 0 Then

BuildIn = ""

Else

For Each varItem In lstItems.ItemsSelected

strOut = strOut & "," & conQuote & _

lstItems.ItemData(varItem) & conQuote

Next varItem

' Get rid of leading comma.

BuildIn = " WHERE " & strFieldName & _

" IN (" & Mid$(strOut, 2) & ")"

End If

End Function

Then, calling this function and passing in a reference to the list box, it
should return a string containing something like "WHERE CustomerID IN
("Item1","Item2","Item3")". You could tag this onto your SQL like this
(assuming that strSQL already contains something like "SELECT * FROM
tblCustomers"):

strSQL = strSQL & _

BuildIn(Me!lstCustomerIDS, "CustomerID")


Now strSQL will contain "SELECT * FROM tblCustomers WHERE CustomerID IN
("Item1","Item2","item3")".

If your items in the list box contain quotes (that is, the double-quote
character), this will fail, and you'll need to find some other way to
delimit the strings from the list box.

=======================================================================
--
( _ /)
(='.'=)
(")-(") .

"Marc" 4cb10cc9$0$10430$
Bonjour à tous

je recherche svp une aide , un module concernant l'utilisation comme
critères pour une requête les entrées choisies dans une zone multi
sélections ?

Merci Bcp M
Publicité
Poster une réponse
Anonyme