snow-raven
Registered User.
- Local time
- Today, 09:42
- Joined
- Apr 12, 2018
- Messages
- 48
I need to output a text CSV file with a consistent table format to another program. This table contains a page number column and must contain a sequential numbering column. I currently generate a row number using method #3 from Access Experts: https://accessexperts.com/blog/2015/07/28/ways-to-do-sequential-numbering-in-access/
My table looks something like:
Data__Page__Row
Data____1____1
Data____1____2
Data____1____3
Data____2____4
Data____2____5
Data____2____6
Sometimes, I want fewer items per page. The key problem is that the first row number of the next page MUST BE CONSISTENT.
WILL NOT WORK:
Data__Page__Row
Data____1____1
Data____1____2
Data____2____3
Data____2____4
Data____2____5
WOULD WORK:
Data__Page__Row
Data____1____1
Data____1____2
Data____2____4
Data____2____5
Data____2____6
WOULD ALSO WORK:
Data__Page__Row
Data____1____1
Data____1____2
Data____2____1
Data____2____2
Data____2____3
I guess I could write some sort of Append query loop to generate a temporary table to achieve this, but that seems clunky. Any suggestions for ways to maybe modify the row numbering module to break the sequence at each page number?
My module:
My row-numbered query (Grad_Plot_Grp is the field I'd like to break on. The user enters 1, 2, etc. to select which page the data will plot on):
My table looks something like:
Data__Page__Row
Data____1____1
Data____1____2
Data____1____3
Data____2____4
Data____2____5
Data____2____6
Sometimes, I want fewer items per page. The key problem is that the first row number of the next page MUST BE CONSISTENT.
WILL NOT WORK:
Data__Page__Row
Data____1____1
Data____1____2
Data____2____3
Data____2____4
Data____2____5
WOULD WORK:
Data__Page__Row
Data____1____1
Data____1____2
Data____2____4
Data____2____5
Data____2____6
WOULD ALSO WORK:
Data__Page__Row
Data____1____1
Data____1____2
Data____2____1
Data____2____2
Data____2____3
I guess I could write some sort of Append query loop to generate a temporary table to achieve this, but that seems clunky. Any suggestions for ways to maybe modify the row numbering module to break the sequence at each page number?
My module:
Code:
Option Compare Database
Option Explicit
'Module to add row numbers field to query
'From YouTube The-Good-Fox
'https://www.youtube.com/watch?v=HWbpzETe-M0
'which takes from: https://accessexperts.com/blog/2015/07/28/ways-to-do-sequential-numbering-in-access/
'#################################
Private lngRowNumber As Long
Private colPrimaryKeys As VBA.Collection
Public Function ResetRowNumber() As Boolean
Set colPrimaryKeys = New VBA.Collection
lngRowNumber = 0
ResetRowNumber = True
End Function
Public Function RowNumber(UniqueKeyVariant As Variant) As Long
Dim lngTemp As Long
On Error Resume Next
lngTemp = colPrimaryKeys(CStr(UniqueKeyVariant))
If Err.Number Then
lngRowNumber = lngRowNumber + 1
colPrimaryKeys.Add lngRowNumber, CStr(UniqueKeyVariant)
lngTemp = lngRowNumber
End If
RowNumber = lngTemp
End Function
'################################
My row-numbered query (Grad_Plot_Grp is the field I'd like to break on. The user enters 1, 2, etc. to select which page the data will plot on):
Code:
SELECT DISTINCTROW Grad_Plot_Query.Grad_Plot_Grp, Project_Info.Project_Name, Project_Info.Project_Number, Collars.Collar_ID, Collars.Collar_Num, Results_Query.Samp_From, Results_Query.Samp_To, Results_Query.Samp_ID, Results_Query.GTest_ID, Grad_Plot_Query.Grd_Plot_Path, RowNumber([Results_Query].[GTest_ID]) AS RowNum, Grad_Plot_Query.Plot_Grad
FROM Project_Info INNER JOIN ((Collars INNER JOIN Results_Query ON Collars.Collar_ID = Results_Query.Collar_ID) INNER JOIN Grad_Plot_Query ON Results_Query.GTest_ID = Grad_Plot_Query.GTest_ID) ON Project_Info.Project_ID = Collars.Project_ID
WHERE (((Grad_Plot_Query.Plot_Grad)=True) AND ((ResetRowNumber())<>False))
ORDER BY Grad_Plot_Query.Grad_Plot_Grp, Collars.Collar_ID;