MS访问字段中每个值的数字
PO_D_TEMP包含几个字段2,其中2个是[Invno]和[lidet_line]。将有许多属于相同[Invno]的行。我希望每个[lidet_line]以1、2等开始,每个[Invno]
示例:[Invno] 1 [lidet_line] 1 [Invno] 1 [getital_line] 2 [Invno] 2 [getital_line] 1 [Invno] 3 [Invno] 3 [ lidet_line] 1等!
我所能弄清的只是一个循环,它为所有记录增加了一个增量数字 - 在每个不同的Invno上都不会重新编号。
这是我拥有的(我在幼儿园级别,对不起):
Private Sub Command1_Click()
Dim db As Database
Set db = CurrentDb()
Dim rstPO_D_Temp As Recordset
Dim strSQL As String
Dim intI As Integer
Dim DetailNum As Integer
'Open a recordset on all records from the PO_D_Temp table
strSQL = "SELECT * FROM PO_D_Temp"
Set rstPO_D_Temp = db.OpenRecordset(strSQL, dbOpenDynaset)
DetailNum = 0
' If the recordset is empty, exit.
If rstPO_D_Temp.EOF Then Exit Sub
intI = 1
With rstPO_D_Temp
Do Until .EOF
.Edit
![Detail_Line] = DetailNum + intI
.Update
.MoveNext
intI = intI + 1
Loop
End With
rstPO_D_Temp.Close
Set rstPO_D_Temp = Nothing
End Sub
PO_D_Temp contains several fields 2 of which are [InvNo] and [Detail_Line].There will be many rows that belong with same [InvNo]. I would like each [Detail_Line] to begin with 1, 2 etc for each [InvNo]
Example: [InvNo]1 [Detail_Line] 1 [InvNo]1 [Detail_Line] 2 [InvNo]2 [Detail_Line] 1 [InvNo]3 [Detail_Line] 1 ETC!
All I have been able to figure out is a loop that adds an incrementing number to ALL records - not renumbering at each different InvNo.
Here is what I have (I am at kindergarten level, sorry):
Private Sub Command1_Click()
Dim db As Database
Set db = CurrentDb()
Dim rstPO_D_Temp As Recordset
Dim strSQL As String
Dim intI As Integer
Dim DetailNum As Integer
'Open a recordset on all records from the PO_D_Temp table
strSQL = "SELECT * FROM PO_D_Temp"
Set rstPO_D_Temp = db.OpenRecordset(strSQL, dbOpenDynaset)
DetailNum = 0
' If the recordset is empty, exit.
If rstPO_D_Temp.EOF Then Exit Sub
intI = 1
With rstPO_D_Temp
Do Until .EOF
.Edit
![Detail_Line] = DetailNum + intI
.Update
.MoveNext
intI = intI + 1
Loop
End With
rstPO_D_Temp.Close
Set rstPO_D_Temp = Nothing
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重置详细编号对于每张发票号码:
Reset the detail no. for each invoice no.: