[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Add item to List Box

Posted on 2004-03-22
8
Medium Priority
?
332 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
6 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

834 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