|
3#
楼主 |
发表于 2022-5-31 21:34:35
|
只看该作者
按六代分组,每组的最大页存入数组 Intsz(结果同查询5)。每条记录的印页在本人页的基础上加上组的最大页,如第一组(1-6世)的印页=页+0,即不变.第二组(7-12世)的印页=页+上组的最大页3,第三组(13-18世)的印页=页+前二组的最大页和,即3+8=11.第四组(19-24世)的印页=页+前三组的最大页和,即3+8+67=78.以此类推.....如果每组最大页有转下页行还要多加一页。我写的代码存在2个问题,一是第6世本为第一组,印页=页,可第6世加了本组的最大页3,2是有转下页行的多加一页没有加页。请帮助。
Private Sub Command25_Click()
CurrentDb.Execute "UPDATE 报表数据源表 SET 报表数据源表.印页 = 0;"
Dim I As Integer
Dim n As Integer
Dim Intsz() As Integer
Dim strsql As String
Dim rst As Object
Dim nn, ww, qq, ttt As Long
nh = 6
qq = nh
strsql = "SELECT Max(报表数据源表.页) AS 页之最大值 FROM 报表数据源表 GROUP BY Partition([世代],1,100," & qq & " ) HAVING (((Partition([世代], 1, 100," & qq & " )) <> False)) ORDER BY Partition([世代],1,100," & qq & ");"
Set rst = CurrentDb.OpenRecordset(strsql)
rst.MoveLast
rst.MoveFirst
n = rst.RecordCount
ReDim Intsz(1 To n)
For I = 1 To n
Intsz(I) = rst("页之最大值")
rst.MoveNext
Next I
Dim rs6 As New ADODB.Recordset
Dim I2 As Long
Dim ssql6 As String
Dim kk1, s, v, f, kp As Integer
Dim j As Integer
ssql6 = "select 世代,页,印页,转下页行 from 报表数据源表 ORDER BY 世代,页 "
rs6.Open ssql6, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs6.MoveLast
rs6.MoveFirst
For I2 = 1 To CLng(rs6.RecordCount)
ww = rs6!世代
s = rs6!页
v = rs6!转下页行
f = Int(ww / 6)
If f = 0 Then
kk1 = 0
Else
If s = Intsz(f) And v > 0 Then
j = 1
Else
j = 0
End If
kk1 = Intsz(f) + j
End If
f = f + 1
rs6!印页 = s + kk1
rs6.Update
rs6.MoveNext
Next I2
rst.Close
Set rst = Nothing
rs6.Close
Set rs6 = Nothing
End Sub |
|