L
LeAnne
Hi all -
I am, and shall ever remain, VBA-impaired. I would very much appreciate
some help translating the following garbage into usable code to
automatically, conditionally transfer Access (97) tables (or query
recordsets) into Excel (97) spreadsheets for archiving purposes. The
problem surfaces when a table (or query) recordset contains >65535
records. Excel 97 truncates the import at this cut-off point. I'm
trying to write a procedure that will count the records in a recordset
if the db object is named "ARCHIVE_*"; then, if there are <= 65535
records, just perform TransferSpreadsheet; if there are more than 65535
records, then run a crosstab query on the table (or query) and export
the results to Excel. Below is my pathetic attempt. Lame, I know. Any
assistance would be greatly appreciated.
PS. Using Acc97 and XL97, as noted. WinXP. I also have Office 2003
loaded on the same desktop, if that's of any use.
tia,
LeAnne
**BAD AIR CODE FOLLOWS**
Do While
TableDef.Name = “ARCHIVE*”
Sub CountRecords()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("ARCHIVE_MyTable")
Debug.Print rst.RecordCount
rst.Close
Set dbs = Nothing
End Sub
Followed by this:
Sub Archive()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
IF CountRecords() <= 65535, Then
‘export table directly to Excel
DoCmd.TransferSpreadsheet acImport, 8, "ARCHIVE_MyTable","[filepath]", True
Else
‘Pivot first…
‘Dim something
‘Set object reference for the pivot recordset
DoCmd.RunSQL “TRANSFORM First(ARCHIVE_MyTable.[valuefield]) " & _
“SELECT ARCHIVE_MyTable.[fieldnames] ” &_
“FROM ARCHIVE_MyTable ” &_
“GROUP BY ARCHIVE_MyTable.[fieldnames] ” &_
“PIVOT ARCHIVE_MyTable.[columnfields];”
‘…Then export pivot recordset to Excel
‘Repeat for all tabledefs of type “ARCHIVE”
Exit Do
End Sub
I am, and shall ever remain, VBA-impaired. I would very much appreciate
some help translating the following garbage into usable code to
automatically, conditionally transfer Access (97) tables (or query
recordsets) into Excel (97) spreadsheets for archiving purposes. The
problem surfaces when a table (or query) recordset contains >65535
records. Excel 97 truncates the import at this cut-off point. I'm
trying to write a procedure that will count the records in a recordset
if the db object is named "ARCHIVE_*"; then, if there are <= 65535
records, just perform TransferSpreadsheet; if there are more than 65535
records, then run a crosstab query on the table (or query) and export
the results to Excel. Below is my pathetic attempt. Lame, I know. Any
assistance would be greatly appreciated.
PS. Using Acc97 and XL97, as noted. WinXP. I also have Office 2003
loaded on the same desktop, if that's of any use.
tia,
LeAnne
**BAD AIR CODE FOLLOWS**
Do While
TableDef.Name = “ARCHIVE*”
Sub CountRecords()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("ARCHIVE_MyTable")
Debug.Print rst.RecordCount
rst.Close
Set dbs = Nothing
End Sub
Followed by this:
Sub Archive()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
IF CountRecords() <= 65535, Then
‘export table directly to Excel
DoCmd.TransferSpreadsheet acImport, 8, "ARCHIVE_MyTable","[filepath]", True
Else
‘Pivot first…
‘Dim something
‘Set object reference for the pivot recordset
DoCmd.RunSQL “TRANSFORM First(ARCHIVE_MyTable.[valuefield]) " & _
“SELECT ARCHIVE_MyTable.[fieldnames] ” &_
“FROM ARCHIVE_MyTable ” &_
“GROUP BY ARCHIVE_MyTable.[fieldnames] ” &_
“PIVOT ARCHIVE_MyTable.[columnfields];”
‘…Then export pivot recordset to Excel
‘Repeat for all tabledefs of type “ARCHIVE”
Exit Do
End Sub