Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a query in VBA, writing to table

Status
Not open for further replies.

be1s

Programmer
Dec 8, 2003
59
0
0
US
Using ADO if possible, I'm insteresting in opening a query as a recordset, loop through the recordset and addNew records to an existing table.

This is what I have so far, but I believe it's using DAO

Dim db As Database
Dim qdf As New QueryDef
Dim rs As Recordset

Dim strQueryName As String

Set db = CurrentDb()

strQueryName = "qry_name"
Set qdf = db.QueryDefs(strQueryName)
Set rs = qdf.OpenRecordset(dbReadOnly)

Do
'here is where I want write to some_table_name
Loop Until rs.eof




 
Why are you saying you want to use ADO yet you are using DAO to open the recordset in the first place ?

What you are talking about doing will work but it will be awfully SLOW.

Why not write an Append query and then just do a DoCmd.RunSQL on the query string ?


Code:
Dim strSQL as String
strSQL = "INSERT INTO tblTarget ( Tfield1, Tfield2 ) " _
       & "SELECT Sfield1, Sfield2 " _
       & "FROM qry_name; "
DoCmd.RunSQL strSQL


'ope-that-'elps.

G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top