Solved

RecordSet to Table?

Posted on 2004-08-06
5
1,413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

691 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