Insert Table Row Loop

  • Thread starter Thread starter DAnte
  • Start date Start date
D

DAnte

I am trying to loop through a listbox and place each value
in a row on one of my tables but I can't seem to set it up
correctly. Basically I have a form that contains a
listbox that will accumulate several rows of text. Once a
button is clicked I would like to insert all the values
from each row in the list box into a new record on a table
and also be able to view them on a form that will be open
while this occurs. I was trying to accomplish this using
a modified version of the code below but I can't seem to
declare a variable as type Database. When I try this I get
an error stating "User-defined type not found"

Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")
' Select all records in the New Customers table
' and add them to the Customers table.
dbs.Execute " INSERT INTO Customers " _
& "SELECT * " _
& "FROM [New Customers];"
dbs.Close

I have also tried to accomplish this by using the
DoCmd.DoMenuItem and DoCmd.GoToRecord methods but nothing
is working. What is the best way to accomplish what I am
trying to do?
 
I am getting a "error accessing registry" error when I try
to when I do this. Is this the only way to fix this
problem?
-----Original Message-----
Go to Tools->References
In References window select DAO ver... (3.5)


-----Original Message-----
I am trying to loop through a listbox and place each value
in a row on one of my tables but I can't seem to set it up
correctly. Basically I have a form that contains a
listbox that will accumulate several rows of text. Once a
button is clicked I would like to insert all the values
from each row in the list box into a new record on a table
and also be able to view them on a form that will be open
while this occurs. I was trying to accomplish this using
a modified version of the code below but I can't seem to
declare a variable as type Database. When I try this I get
an error stating "User-defined type not found"

Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")
' Select all records in the New Customers table
' and add them to the Customers table.
dbs.Execute " INSERT INTO Customers " _
& "SELECT * " _
& "FROM [New Customers];"
dbs.Close

I have also tried to accomplish this by using the
DoCmd.DoMenuItem and DoCmd.GoToRecord methods but nothing
is working. What is the best way to accomplish what I am
trying to do?
.
.
 
Back
Top