How do I insert record into the table from recordset?

S

Sunny

In vba code, How can I insert recrds into one table from recordset defined
earlier in the code. I want something like this:

Dim rsClient As Recordset
Dim stSQL As String

Set rsClient = CurrentDb.OpenRecordset(Name:="Clients", Type:=dbOpenDynaset)
stSQL = "INSERT INTO TEMPCLIENT1 SELECT * FROM rsClient" 'rsClient is
not a table in database it is recordset set in previous line
CurrentDb.Execute (stSQL)

Any other alternative?
Thanks.
 
C

Chris Nebinger

Dim rsClient as DAO.Recordset
Dim dbs as DAO.Database
dim fld as New Field
Dim rs as DAO.Recordset
Set dbs=CurrentDB

Set rsClient = dbs.OpenRecordset(Name:="Clients",
Type:=dbOpenDynaset)
set rs = dbs.OpenRecordset ("Select * from tempClient1")
Do until rsClient.Eof
rs.AddNew
For Each fld in rsClient.Fields
rs(fld.name)=fld.value
Next fld
rs.update
rsClient.MoveNext
Loop


Chris Nebinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top