?
Solved

Add item to List Box

Posted on 2004-03-22
8
Medium Priority
?
326 Views
Last Modified: 2008-03-04
I have a List Box with 4 columns,

And I insert the data with command

lst1.AddItem rst!col1 & ";" & rst!col2 ...(where rst is recordset)

If the rst!col1 will contain ";" (this specific character,for example "text1;text2" ) it will not work correctly.

How can I fix this problem

Thanks.
0
Comment
Question by:Irina_dusha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 10647948
do you want to replace that semicolon with another character

if so, you can use the Replace command

newText = Replace(OldText,"ReplaceFrom","ReplaceTo"

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 400 total points
ID: 10647968
or you could do this, which is probably better

lst1.AddItem chr$(34) & rst!col1 & chr$(34) & ";" & chr$(34) & rst!col2 & chr$(34) & ";" ....

stick chr$(34) - equivalent of double quotes, around the field
0
 

Author Comment

by:Irina_dusha
ID: 10647977
No ,I want that ";" character will stay
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 4

Expert Comment

by:matt150279
ID: 10648009
The AddItem method doesnt work full stop in MS-Access, to my understanding.

To fill a listbox in this way you would need to set the rowsourcetype property to 'Value List' and then use code like this:-

lst1.rowsource = rst!col1 & ";" etc etc..

That should work.  The AddItem method is Visual Basic only.
0
 

Author Comment

by:Irina_dusha
ID: 10648017
to rockiroads,I didn't understand your solution ??
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 10648036
lst1.AddItem chr$(34) & rst!col1 & chr$(34) & ";" & chr$(34) & rst!col2 & chr$(34) & ";" ....

chr$(34) is the same as a double quote

what we are doing is wrapping our field with double quotes. This should then force it to take the full value and not interpret the field

I did a little test, created a value list listbox, defined some constants

Private Const X1 = "rst1"
Private Const X2 = "rs;t2"
Private Const X3 = "rst3"
Private Const X4 = "rst4"


    List1.RowSource = X1 & ";" & X2 & ";" & X3 & ";" & X4

produced 2 rows instead of one - it used the semi-colon as defined in X"


    List1.RowSource = Chr$(34) & X1 & Chr$(34) & ";" & Chr$(34) & X2 & Chr$(34) & ";" & Chr$(34) & X3 & Chr$(34) & ";" & Chr$(34) & X4 & Chr$(34)

produced just 1 row - and the 2nd column contained rs;t2
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question