add records to a table from a recordset

G

Guest

i am creating a recordset in code that I want to dump into a table so I can
pull from it in a query. is this possible? how?
here is the code i have to create the recordset...

Set qd = con.CreateQueryDef("", sql8)
Set rs = qd.OpenRecordset

With rs
I = 1
'Dim PlantInfo(30, 6) As Variant
Dim OutageType(1000, 30)
Dim StartDate(1000, 30)
Dim EndDate(1000, 30)
Dim MWBefore(1000, 30)
Dim MWAfter(1000, 30)
Dim NERCID(1000, 30)
Dim CAUSECODE(1000, 30)
Dim COMPID(1000, 30)
Dim OUTAGENUMBER(1000, 30)
Dim Extreme(30, 2) As Date ' 1 is the start,
Dim kay(30) As Integer
For aka = 1 To Numplants
kay(aka) = 0
Next aka

Do While Not .EOF
j = 1
pick = "maybe"
Do While pick = "maybe"
If (!NERC_UNIT_ID) = PlantInfo(j, 2) Then
pick = "yes"
plantdex = j
End If
If j > Numplants Then
pick = "no"
End If
j = j + 1
Loop

If pick = "yes" Then

kay(plantdex) = kay(plantdex) + 1
OutageType(kay(plantdex), plantdex) = (!OUTAGE_TYPE)
StartDate(kay(plantdex), plantdex) = (!START_DATE)

EndDate(kay(plantdex), plantdex) = (!END_DATE)
MWBefore(kay(plantdex), plantdex) = (!MW_BEFORE_RED)
MWAfter(kay(plantdex), plantdex) = (!MW_REDUCTION)
NERCID(kay(plantdex), plantdex) = (!NERC_UNIT_ID)
OUTAGENUMBER(kay(plantdex), plantdex) = (!OUTAGE_NUMBER)

End If


I = I + 1
.MoveNext
Loop
End With
 
G

Guest

You are never touching the recordset except to move from record to record.
You are moving about some multidimensional arrays, but I don't see how that
could possibly relate to putting data into your table. A field in a table
can and should hold only one piece of data. Since I don't know what you are
trying to put in the table, I can't be specific, but here is the basic way to
use recordset processing to get data into a table:

First, you have to either add a new record or select the record you want to
change. I will ignore navigating to a specific record for the moment. If you
want to add a new record, the syntax is:
rs.AddNew
To edit an existing record:
rs.Edit
To put a memory variable into a field:

rs![SomeField] = strSomeVariable

Once all the fields have been populated, you need to update the record:

rs.Update
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top