[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

RecordSet to Table?

Posted on 2004-08-06
5
Medium Priority
?
1,427 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 100 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

830 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