Solved

RecordSet to Table?

Posted on 2004-08-06
5
1,370 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
Comment Utility
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
Comment Utility
I would love this.

the recordset is ADO
0
 
LVL 39

Expert Comment

by:stevbe
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now