Converting a list into a string format

Hi
  I'm developing part of an application where there are 2 list boxes. In one of the list boxes there is a list of choices that the user can choose. Once the user has picked something from the list it goes into the second list box. The problem is that when the information is sent to the database, the database can't read it because it reads it in a string format. Meaning that if the items in the list are 1,2,3,4.. the database can only read it as 1,2,3,4..not                               1
                                           2
                                           3
                                           4.

How do i convert the list format above into a string with commas in between all the choices?  

Thanks in advance
nebula786Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vbWayneConnect With a Mentor Commented:


'run it and see if it's what you want
'Tim has given you 1,2,3,4

strList = ""
For intcount = 0 To List1.ListCount - 1
  List1.ListIndex = intcount
  strList = strList & List1.Text & IIf(intcount = List1.ListCount - 1, "", ",")
  iarray(intcount) = strList
Next


MsgBox strList
0
 
nebula786Author Commented:
Edited text of question.
0
 
TimCotteeCommented:
IF I understand correctly then this should do the trick,

strList = ""
For intCount = 0 to List2.ListCount - 1
  List2.ListIndex = intCount
  strList = strList & List2.Text & iif(intCount = List2.ListCount - 1,"",",")
Next

Though I can never remember whether listindex is 0 based or 1 based so you may need to change it to 1 to list2.listcount instead etc.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
vbWayneCommented:
What exactly do you mean?
1,2,3,4 are the values or the list index
0
 
nebula786Author Commented:
What do you mean you might have to change it to 1 to list2.listindex?
0
 
matrix717Commented:
If I I understood is right, you want to record in the database what the user choose from the listbox, so if this is the case this should works:

Dim base1 as database
dim record1 as recordset

set base1=opendatabase("Whatever\yourdatabase.mdb")

set record1=base1.openrecordset("yourrecordset",2)

with record1

..addnew
!fieldname = list1
..update

end with


This will save what the user selected from the listbox

0
 
TimCotteeCommented:
Seems like the accepted answer is just a variation on my original!
0
 
vbWayneCommented:
I agree...
it wasn't meant to be the answer it was a statement in reference to...
From: nebula786
 Date: Friday, January 14 2000 - 08:00AM PST  ....
I worded it as this....
look at what Tim has sent you and see if it's what you need...

Wayne

ps..Sorry about the misunderstanding Tim, I wasn't after your points I was advising nebula786 to check out your answer because it was what he/she needed and

0
 
TimCotteeCommented:
Didn't mean to have a go at you Wayne, but well these things happen, I guess if nebula786 felt so inclined he/she could contact customer service and sort it out but it don't matter that much to me as long as the problem is sorted.
0
 
nebula786Author Commented:
I apologize Tim. This was my first time asking a question, and accepting an answer. I thought I could accept both answers. Sorry for the misunderstanding.  
0
 
nebula786Author Commented:
I've contacted customer service. Hopefully this problem will be taken care of. Once again, I apologize.
0
 
darinwCommented:
I apologize for the very long delay in answering your post in the Customer Service area nebula786.

I will post a question for Tim in this section for the appropriate points.

darinw
Customer Service
0
 
vbWayneCommented:
Coool...:}
0
All Courses

From novice to tech pro — start learning today.