cowspotter
New member
- Local time
- Today, 01:55
- Joined
- Aug 13, 2008
- Messages
- 8
I am trying to parse though a table which contains user activity for a week. I am running a query against the table which returns the unique user ids that i will generate reports for. These results fill idRS (recordset). I then loop through each one filling activityRS with just that IDs activity. I have a sub that I found which exports the provided recordset as an excel document. The problem I have is that there are times where a given ID will have more than 50,000 rows. Its entirely possible for an ID to have >150,000 records. Because of Excels row limit I need to be able to split the recordset across multiple excel files. These files are provided to users so i can't just have them open the files in access. How do I split a 150,000 recordset into 3 identically formed recordsets (ie. Fields) with each set having 50,000 rows each. Here's the code I have so far. I haven't included the export to excel sub but if you need that, just let me know:
Public Function CreateReports()
Dim db As Database
Dim idRS As Recordset
Dim rsField As Field
Dim activityRS As Recordset
Dim activityRS1 As Recordset
Dim activityRS2 As Recordset
Dim activityRS3 As Recordset
Dim activityRS4 As Recordset
Dim count As Integer
Set db = CurrentDb()
Set idRS = db.OpenRecordset("SELECT [All Data 2].[DB User Name] As user_name FROM [All Data 2] GROUP BY [All Data 2].[DB User Name];", dbOpenDynaset, dbDenyRead)
If Not (idRS.BOF And idRS.EOF) Then
idRS.MoveFirst
Do While Not idRS.EOF
Set activityRS = db.OpenRecordset("SELECT [All Data 2].* FROM [All Data 2] WHERE [All Data 2].[DB User Name] = '" & idRS("user_name") & "';", dbOpenDynaset, dbDenyRead)
activityRS.MoveLast
count = activityRS.RecordCount
activityRS.MoveFirst
If count < 50000 Then
SaveAsExcel activityRS
ElseIf count >= 50000 And count < 100000 Then
ElseIf count >= 100000 And count < 150000 Then
ElseIf count >= 150000 And count < 200000 Then
End If
idRS.MoveNext
Loop
End If
End Function
____________________________
The numbered activityRS recordsets are what I created to hold the split recordset data, just don't know how to go about splitting the data.
Public Function CreateReports()
Dim db As Database
Dim idRS As Recordset
Dim rsField As Field
Dim activityRS As Recordset
Dim activityRS1 As Recordset
Dim activityRS2 As Recordset
Dim activityRS3 As Recordset
Dim activityRS4 As Recordset
Dim count As Integer
Set db = CurrentDb()
Set idRS = db.OpenRecordset("SELECT [All Data 2].[DB User Name] As user_name FROM [All Data 2] GROUP BY [All Data 2].[DB User Name];", dbOpenDynaset, dbDenyRead)
If Not (idRS.BOF And idRS.EOF) Then
idRS.MoveFirst
Do While Not idRS.EOF
Set activityRS = db.OpenRecordset("SELECT [All Data 2].* FROM [All Data 2] WHERE [All Data 2].[DB User Name] = '" & idRS("user_name") & "';", dbOpenDynaset, dbDenyRead)
activityRS.MoveLast
count = activityRS.RecordCount
activityRS.MoveFirst
If count < 50000 Then
SaveAsExcel activityRS
ElseIf count >= 50000 And count < 100000 Then
ElseIf count >= 100000 And count < 150000 Then
ElseIf count >= 150000 And count < 200000 Then
End If
idRS.MoveNext
Loop
End If
End Function
____________________________
The numbered activityRS recordsets are what I created to hold the split recordset data, just don't know how to go about splitting the data.