G
Guest
I have a persisted recordset, created in VBA with ADO using
rst.save strFileName adPersistADTG
I would like to be able to INSERT INTO (i.e. append) an Access table
strTableName. I don't know if it's possible, or if I'm just doing this wrong.
From the Access VBE my code for the INSERT INTO is:
strPathFileName = c:\work\Thefile.rst
strSQL_FROM = "SELECT * FROM [" & strPathFileName & "]"
strSQL = ""
strSQL = strSQL & "INSERT INTO " & strTableName & " "
strSQL = strSQL & strSQL_FROM
With connTo
.Execute strSQL
.Close
End With
If I have
set connTo = CurrentProject.connection
I get "-2147217865: The Microsoft Jet database engine cannot find the input
table or query 'c:\work\Thefile.rst'. Make sure it exists and that its name
is spelled correctly."
I can retrieve it fine - back into a recordset using
With connFrom
.Provider = "MSPERSIST"
.Open
End With
Set rst = New ADODB.Recordset
With rst
.Open strPathFileName, connFrom, , , adCmdFile
End With
The rst is then ready for business - but I can't use it directly in the
INSERT INTO statement.
I know that I can take the recordset and feed, row by row, into a new
recordset opened from the destination table, but I'd like to do this as a
Batchupdate with INSERT INTO if at all possible.
I haven't been able to find any examples of how to do this.
Why am I using a persisted recordset, anyway?
I would like to see if it is any quicker than using the rst.updatebatch for
inserting data from the web (with 500,000 + rows) directly into the
destination table. I'm currently doing that using
rst_INTO.Filter = adFilterPendingRecords
rst_INTO.UpdateBatch
at intervals of 100 records. I don't want to leave it all to the end to
append - because I don't want to risk getting the data, and then it crashing
with a huge append. I suspect that as the table gets larger (from the
..updateBatch) it gets less efficient, because of the existing (and
continuously updating) indexes.
It may be that creating a persisted recordset and then trying to INSERT it
INTO the Access table is just as slow, but I'd sure like to try (or have it
confirmed for me).
rst.save strFileName adPersistADTG
I would like to be able to INSERT INTO (i.e. append) an Access table
strTableName. I don't know if it's possible, or if I'm just doing this wrong.
From the Access VBE my code for the INSERT INTO is:
strPathFileName = c:\work\Thefile.rst
strSQL_FROM = "SELECT * FROM [" & strPathFileName & "]"
strSQL = ""
strSQL = strSQL & "INSERT INTO " & strTableName & " "
strSQL = strSQL & strSQL_FROM
With connTo
.Execute strSQL
.Close
End With
If I have
set connTo = CurrentProject.connection
I get "-2147217865: The Microsoft Jet database engine cannot find the input
table or query 'c:\work\Thefile.rst'. Make sure it exists and that its name
is spelled correctly."
I can retrieve it fine - back into a recordset using
With connFrom
.Provider = "MSPERSIST"
.Open
End With
Set rst = New ADODB.Recordset
With rst
.Open strPathFileName, connFrom, , , adCmdFile
End With
The rst is then ready for business - but I can't use it directly in the
INSERT INTO statement.
I know that I can take the recordset and feed, row by row, into a new
recordset opened from the destination table, but I'd like to do this as a
Batchupdate with INSERT INTO if at all possible.
I haven't been able to find any examples of how to do this.
Why am I using a persisted recordset, anyway?
I would like to see if it is any quicker than using the rst.updatebatch for
inserting data from the web (with 500,000 + rows) directly into the
destination table. I'm currently doing that using
rst_INTO.Filter = adFilterPendingRecords
rst_INTO.UpdateBatch
at intervals of 100 records. I don't want to leave it all to the end to
append - because I don't want to risk getting the data, and then it crashing
with a huge append. I suspect that as the table gets larger (from the
..updateBatch) it gets less efficient, because of the existing (and
continuously updating) indexes.
It may be that creating a persisted recordset and then trying to INSERT it
INTO the Access table is just as slow, but I'd sure like to try (or have it
confirmed for me).