Solved

RecordSet to Table?

Posted on 2004-08-06
5
1,394 Views
Last Modified: 2008-05-22
Is there a simple way to output or write a RecordSet to a Table?
0
Comment
Question by:rrr333222
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:stevbe
ID: 11737737
Not a simple one line command or function. Would you like some help with code to create a table / populate a table? What kind of a recordset do you have? ADO or DAO?

Steve
0
 

Author Comment

by:rrr333222
ID: 11737837
I would love this.

the recordset is ADO
0
 
LVL 39

Expert Comment

by:stevbe
ID: 11737973
Is this related to your last question about setting recordsource property of a report ... is this the data you want added to a table? If so please post the SQL you are using for the report and we can build an insert into which will build and popuate the table for you.

If it is a recordset that exists only in memory or you are making changes to it after you open it but do not want the results stored with the original data ...

I would suggest that you keep a table around specifically for this recordset as that code gets quite long. Now open a recordset of the template table and loop through the in memory recordset and add each record, field by field, into the template table recordset.

Please let me know which direction you need to go with ... yiur original recordset is based on a table/query without any aditional changes that cannot be done in SQL or the original recordset lives in memory only.

Steve
0
 

Author Comment

by:rrr333222
ID: 11738127
If it is a recordset that exists only in memory or you are making changes to it after you open it but do not want the results stored with the original data ...

this is where i'm coming from. related to earlier question but i didn't understand correctly the situation here. so i have a recordsource that is in memory and needs to b changed for before it gets to the report.

0
 
LVL 39

Accepted Solution

by:
stevbe earned 25 total points
ID: 11742295
ok ... so a temp table it is ... just pass your recordset after you have made the changes to this function ...

Public Function AddToTable(adoRec As ADODB.Recordset)

Dim rst As ADODB.Recordset
Dim fld As ADODB.Field

'first clear out any old data in the temp table
CurrentDb.Execute "DELETE * FROM tblTemp"

'now open a recordset of that table so you can add new records
Set rst = New ADODB.Recordset
rst.Open Source:="SELECT * FROM tblTemp", _
         ActiveConnection:=CurrentProject.Connection, _
         CursorType:=adOpenKeyset, _
         LockType:=adLockOptimistic

'now loop through the recordset you passed in and add
'each record to the temp table
adoRec.MoveFirst
Do While Not adoRec.EOF
    rst.AddNew
        For Each fld In adoRec.Fields
            rst.Fields(fld.Name).Value = fld.Value
        Next
    rst.Update
    adoRec.MoveNext
Loop

'cleanup
rst.Close
Set rst = Nothing

End Function

Steve
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question