multi-select list in access

R

ria

I have written the code below but, it is not working.
PLease help.

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

The data I use is text. I am using the data in Me!Text19
in the query.....

Thank you
 
D

Douglas J. Steele

What's the "\""" for? That's going to put the literal \" in your string: is
that what you want? I suspect you simply want quotes around the text.

strSQL = strSQL & ctl.ItemData(varItem) & """" & "," & """"

or

strSQL = strSQL & ctl.ItemData(varItem) & """, """

or

strSQL = strSQL & ctl.ItemData(varItem) & Chr$(34) & "," & Chr(34)

Exagerated for clarity, the first 2 are:

strSQL = strSQL & ctl.ItemData(varItem) & " " " " & "," & " " " "


or

strSQL = strSQL & ctl.ItemData(varItem) & " " ", " " "
 
G

Guest

Thankyou...the eason I am putting the quotes is because if
I don't, access is treating the whole field along with the
commas as one.
 

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