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
Printable View
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
Here is a simple way to do it using SQL:
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).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