Dim H1 As DAO.Recordset, H2 As DAO.Recordset
Set H1 = CurrentDb.OpenRecordset("SELECT * FROM 統計表 ORDER BY 年度 ASC")
Set H2 = CurrentDb.OpenRecordset("資料表")
Dim NM1 As String
If H1.RecordCount > 0 Then
H1.MoveFirst
For R1 = 1 To H1.RecordCount
If NM1 <> "" And NM1 = H1("年度") Then
V = V + 1
ElseIf NM1 <> H1("年度") Then
V = 1
End If
H2.AddNew
H2("SA1") = V
H2("SA3") = H1("年度")
H2("SA2") = H1("日期")
NM1 = H1("年度")
H2.Update
H1.MoveNext
Next
End If
以上的程式.可以在("資料表")中查到群組的筆數.
問題:如何控制每個群組的紀錄筆數是30的倍數.
ex:("資料表")中有年度(2002)的筆數 是35筆.
如何做到讓2002的筆數成為是60.而且新增出來的筆數只要有年度的資料就可以了.
年度(2003)的筆數 是30筆.不必新增.
年度(2005)的筆數 是15筆.新增至30筆.
**請不要侷限在2002至2005.因為群組範圍並非是2003到2005固定變化的資料.**
2006-10-10 05:25:36 · 2 個解答 · 發問者 大樹鄉 4 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() Dim H1 As DAO.Recordset, H2 As DAO.Recordset Set H1 = CurrentDb.OpenRecordset("SELECT * FROM 統計表 ORDER BY 年度 ASC") Set H2 = CurrentDb.OpenRecordset("資料表") Dim NM1 As String, V As Long If H1.RecordCount > 0 Then H1.MoveFirst Do Until H1.EOF If NM1 = H1("年度") Then V = V + 1 Else Call nADD(H2, NM1, V) End If H2.AddNew H2("SA1") = V H2("SA3") = H1("年度") H2("SA2") = H1("日期") NM1 = H1("年度") H2.Update H1.MoveNext Loop End If Call nADD(H2, NM1, V)End SubSub nADD(ByVal H2 As DAO.Recordset, ByVal NM1 As String, ByRef V As Long) If NM1 <> "" Then Do While V Mod 30 V = V + 1 H2.AddNew H2("SA1") = V '此行視你須要與否可刪除 H2("SA3") = NM1 H2.Update Loop End If V = 1End Sub
2006-10-10 22:29:37 補充:
別客氣XD
2006-10-11 01:59:12 補充:
別這麼說,大家教學相長,若不嫌在下雞婆,很歡迎您提出問題大家一起討論.
2006-10-10 15:41:28 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
W.J.S:
你好!謝謝你的指導.
稍後.回報.再次說聲謝謝!!
2006-10-10 16:07:07 · answer #2 · answered by 大樹鄉 4 · 0⤊ 0⤋