Results 1 to 2 of 2

Thread: Listbox problem pls help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Location
    Edmonton,AB,Canada
    Posts
    28
    Hi All,

    How do I save multiple items(at once)in the list box to an Access table?

    I Have a listbox contained more than one customer names, I would like to write all the names to the access table at one click of the button.


    Thanks

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Here is a simple way to do it using SQL:

    Code:
    Private Sub SaveList() 
      Dim db as Database
      Dim strSQL as String
      dim i as Integer
    
       Set db = DBEngine.OpenDatabase("C:\MyDBPath.mdb")
        
        For i = 0 to (List1.ListCount - 1)
           
           'assuming that the name of the table is Customers 
           'and the name of the field to accept the data is CustomerName
           strSQL = "INSERT INTO Customers (CustomerName) VALUES ('" & List1.List(i) & "');"
           Call db.Execute(strSQL)
    
         next i
    
        db.Close
    
    End Sub
    of course you will have to customize some of the parameters to match your database (i.e. the path of the actual database, the names of the table and field to insert the new names).



    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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