Adding text to listbox not working properly [RESOLVED]

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Adding text to listbox not working properly [RESOLVED]

Post by Abraxus »

I am creating a GUI for users to build queries.

They select from the available fields and set the criteria and for each criteria click ADD and it puts the criteria WHERE value in a List Box.

I'm running into an issue where this
FORMAT([Date],'YYYYMMDD') BETWEEN '20100503' AND '20100526'
which should be added as one line is appearing as 2 items in the List Box. The 2 lines look like this:
FORMAT([Date]
and
YYYYMMDD
How do I get it to add the entire string to my List Box as one line?

My actual code is:

Code: Select all

Me.lstSelectedCriteria.AddItem "FORMAT([Date],'YYYYMMDD') BETWEEN '20100503' AND '20100526'"
Last edited by Abraxus on 26 May 2010, 14:21, edited 1 time in total.
Morgan

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Adding text to listbox not working properly

Post by HansV »

Access treats commas as column separators. To get around this problem, enclose the entire string in extra quotes, e.g.

Me.lstSelectedCriteria.AddItem Chr(34) & "FORMAT([Date],'YYYYMMDD') BETWEEN '20100503' AND '20100526'" & Chr(34)

or

Me.lstSelectedCriteria.AddItem """FORMAT([Date],'YYYYMMDD') BETWEEN '20100503' AND '20100526'"""
Best wishes,
Hans

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Re: Adding text to listbox not working properly

Post by Abraxus »

Perfect, thank you!
Morgan