updated hlp with multi-select query

R

ria

I am trying to use the multiple selections from a lift (in
a form) to query a table. I have written the code below
but, it only works for one selection. If I make more than
1 selection, the result is nothing. Does anyone have a
solution? The selction data I use is text. I am using the
data in Me!Text19 (control box) in the query.....


Private Sub List14_Exit(Cancel As Integer)
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String

Set frm = Forms!DateRangeDialog
Set ctl = frm!List14

strSQL = ""
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & "\""" & ","
& "\"""
strSQL = Left$(strSQL, Len(strSQL) - 5) +
Mid$(strSQL, Len(strSQL) - 3, 2) + Right$(strSQL, 1)

Next varItem

'Trim the end of strSQL
strSQL = Left$(strSQL, (Len(strSQL) - 3))

Me!Text19 = strSQL
End Sub


Thank you
..
 
M

Michel Walsh

Hi,


and if you comment the Left$, Mid$, Right$ formula, what do you got? It
seems you remove too many characters in that... studious... formula. (It
seems it removes the last two characters from ctl.ItemData(varItem), but in
a very complicated way to do it).


I assume the list box is a MultiSelect <> "None".




Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top