Results 1 to 7 of 7

Thread: [RESOLVED] Add Listbox Items into a table

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    29

    Resolved [RESOLVED] Add Listbox Items into a table

    How can I add items in a Listbox into an SQL table??

  2. #2
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Add Listbox Items into a table

    you can use a for loop and an sql statement executed in ado for that purpose

    VB Code:
    1. if List1.ListCount > 0 then
    2.     Dim a as Long
    3.     for a = 0 to List1.ListCount - 1
    4.         cn.execute "insert into statement here to insert the data from the listbox to the db"
    5.     Next
    6. End If
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    29

    Re: Add Listbox Items into a table

    This doesn't seem to work

    Actually I hav to add the raw materails used in a product

    I'm doing something as follows:

    rs.AddNew
    rs!prod_name = txtname
    rs!raw material = lstRM.List(lstRM.ListIndex)

    rs.Update

    I know this code is wrong.

    Please suggest some code that is appropriate with this method

    rs.AddNew
    rs!prod_name = txtname
    rs!raw material = lstRM.List(lstRM.ListIndex)

    rs.Update

    Thx..

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Add Listbox Items into a table

    just put this into a loop

    VB Code:
    1. For i = 0 To lstRM.ListCount -1
    2.     rs.AddNew
    3.     rs!prod_name = txtname
    4.     rs!raw material = lstRM.List (i)
    5.     rs.Update
    6. Next

    just give a try and post if anything else
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    29

    Re: Add Listbox Items into a table

    For i = 0 To lstRM.ListCount -1
    rs.AddNew
    rs!prod_name = txtname
    rs!raw material = lstRM.List (i)
    rs.Update
    Next

    this is generating an error '3265'

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    29

    Re: Add Listbox Items into a table

    Sorry I solved that error.

    But this method only seems to add the last item in the list.

    Is there any way of adding all the items in the list into the table??

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    29

    Re: Add Listbox Items into a table

    Thx every1 for ur help.

    I found the solution.

    I thought I should post it.

    Dim rm As String
    Dim a as Integer
    For a = 0 To list1.ListCount-1
    rm = rm & list1.List(a)
    Next
    rs!RM = rm

    rs.Update

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width