?
Solved

RecordSet to Table?

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

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