473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Access 2003 - How to show ValueList listbox data containing commas?

Hello world:

I have a ListBox that I fill as a ValueList from a SQL query. The SQL looks
like:

SELECT Format(COST,"$#,000") As ItemCost FROM tblPricing ...

I put semicolons between each entry before I load it into the ListBox.
However, if my entry has a comma in it ($2,500 for example) Access adds
another column, thereby messing up the ListBox display. It shows as $2 and
then 500.

Why is Access using a comma as an list separator, when it is only supposed
to use semicolons? Is there any way to escape the comma, and have it be
accepted as just another character in the ListBox display?

Thanks in advance for any help offered.

Alan
Nov 13 '05 #1
4 10332
rkc
Alan Lane wrote:
Hello world:

I have a ListBox that I fill as a ValueList from a SQL query. The SQL looks
like:

SELECT Format(COST,"$#,000") As ItemCost FROM tblPricing ...

I put semicolons between each entry before I load it into the ListBox.
However, if my entry has a comma in it ($2,500 for example) Access adds
another column, thereby messing up the ListBox display. It shows as $2 and
then 500.

Why is Access using a comma as an list separator, when it is only supposed
to use semicolons? Is there any way to escape the comma, and have it be
accepted as just another character in the ListBox display?


Trying enclosing each item in quotes.

Function escapeListItem(ByVal s As String) As String
escapeListItem = Chr$(34) & s & Chr$(34)
End Function
Access.Version > 97 = .AddItem (escapeListItem(rs!ItemCost))



Nov 13 '05 #2
Alan Lane wrote:
I put semicolons between each entry before I load it into the ListBox.
However, if my entry has a comma in it ($2,500 for example) Access adds
another column, thereby messing up the ListBox display. It shows as $2 and
then 500.


Commas and semi-colons are used. In cases like this, I delimit my
values with double quotes. So, for example (air code), using DAO::

Sub sPopulateList

dim dbs as DAO.database
dim rst as DAO.recordset
dim strS as string
dim strList as string 'value list

set dbs = access.currentdb

'I'm not using any where clause below.
'Note the double quotes in the format function

strs = "SELECT Format(COST,""$#,000"") As ItemCost FROM tblPricing"

set rst = dbs.openrecordset(strs, dbopensnapshot)

with rst

if .eof then

'slap in some message for no records found

else

.movefirst

strlist = ""

do while .eof = false

if strList <> "" then strlist = strList & ";"

'Chr(34) is the ascii code for "

strList = chr(34) & .fields!ItemCost & Chr(34)

.movenext

loop

end if

end with

'populate the value list

me.lstMyListBox.Rowsource = strList

Exit_Proc:

rst.close

set rst = nothing

dbs.close

set dbs = nothing

End Sub
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #3
Hello Tim and rkc:

Thanks for the help from both of you. The double-quotes idea didn't work
for me, unfortunately. I took another part of both your suggestions,
though, and used "Chr(34)" before and after the ItemCost, when entering it
into the ListBox's ValueList. That worked like a charm!

Alan

"Tim Marshall" <TI****@PurplePandaChasers.Moertherium> wrote in message
news:d9**********@coranto.ucs.mun.ca...
Alan Lane wrote:
I put semicolons between each entry before I load it into the ListBox.
However, if my entry has a comma in it ($2,500 for example) Access adds
another column, thereby messing up the ListBox display. It shows as $2
and then 500.


Commas and semi-colons are used. In cases like this, I delimit my values
with double quotes. So, for example (air code), using DAO::

Sub sPopulateList

dim dbs as DAO.database
dim rst as DAO.recordset
dim strS as string
dim strList as string 'value list

set dbs = access.currentdb

'I'm not using any where clause below.
'Note the double quotes in the format function

strs = "SELECT Format(COST,""$#,000"") As ItemCost FROM tblPricing"

set rst = dbs.openrecordset(strs, dbopensnapshot)

with rst

if .eof then

'slap in some message for no records found

else

.movefirst

strlist = ""

do while .eof = false

if strList <> "" then strlist = strList & ";"

'Chr(34) is the ascii code for "

strList = chr(34) & .fields!ItemCost & Chr(34)

.movenext

loop

end if

end with

'populate the value list

me.lstMyListBox.Rowsource = strList

Exit_Proc:

rst.close

set rst = nothing

dbs.close

set dbs = nothing

End Sub
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me

Nov 13 '05 #4
Alan Lane wrote:
Hello Tim and rkc:

Thanks for the help from both of you. The double-quotes idea didn't work
for me, unfortunately. I took another part of both your suggestions,
though, and used "Chr(34)" before and after the ItemCost, when entering it
into the ListBox's ValueList. That worked like a charm!

You actually can put double quotes in using _double_ double quotes (boy,
does that sound confusing). It can be difficult to keep track of and
when I can't be bothered, I find the use of chr(34) easier.

another useful delimiter (though not for list/combo box rowsources) is
chr(35) which is #.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: sheree | last post by:
I would like to create a query where one of the columns of the queries comes from a combo list box on a form. For example, if my table has the following fields: id name interest1 interest2...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
6
by: AAJ | last post by:
Hi all I have a listbox on a form. If I set its rowsource directly, and the query in the rowsourse returns no data, then the displayed listbox is empty (exactly as you would expect) ...
3
by: Alan Lane | last post by:
Hello world: I have a Parent form with a combobox, where the user selects a Contract or Estimate number. Then, on a subform, I have a listbox that gets filled with the details of the selected...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: awmb | last post by:
Language C#, Version ASP.Net 2.0 Hi I have a GridView which is bound to a table which contains Restaurant information. In the Edit Row there is a Listbox (ListBox1) in the Food Type column,...
4
by: zufie | last post by:
I have a main form containing a command SEND button that prompts an email form to pop up. The email address(es) that are supposed to appear on the email form are those corresponding to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.