Solved

Add item to List Box

Posted on 2004-03-22
8
288 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
  • 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 100 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now