Solved

Add item to List Box

Posted on 2004-03-22
8
318 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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