DataTables("税务销售").LoadFilter = "单据编码 Is Null"
DataTables("税务销售").Load()
Tables("税务销售").Sort = "税务年度,销方名称 DESC"
Dim t1 As Table = Tables("税务销售")
Dim cn As Integer = t1.Rows.Count - 1
Dim k As Integer = 1
Dim s As Row
For i As Integer = 0 To cn
If t1.Rows(i)("开piao日期") = Nothing Then
t1.Rows(i)("单据编码") = Nothing
Else
Dim d As Date = t1.Rows(i)("开piao日期")
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y, m)
Dim fd As Date = New Date(y, m, 1) '获得该月的第一天
Dim ld As Date = New Date(y, m, Days) '获得该月的最后一天
Dim bh As String = Format(t1.Rows(i)("开piao日期"), "yyyyMM") '取得编号的6位前缀
'If t1.Rows(i)("单据编码").StartsWith(bh) = False Then'如果编号的前6位不符
Dim max As String
Dim idx As Integer
max = DataTables("税务销售").sqlCompute("Max(单据编码)", "开piao日期 >= #" & fd & "# And 开piao日期 <= #" & ld & "# And [_Identify] <> " & t1.Rows(i)("_Identify")) '取得该月的最大编号
MessageBox.Show(max)
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(7, 3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
If t1.Rows(i)("购买方名称") <> t1.Rows(i - 1)("购买方名称") Then
t1.Rows(i)("单据编码") = bh & Format(idx, "000")
Else
t1.Rows(i)("单据编码") = t1.Rows(i - 1)("单据编码")
End If
'End If
End If
Next
MessageBox.Show("已完成")
下边求不出最大的编号,弹出窗口为空值
max = DataTables("税务销售").sqlCompute("Max(单据编码)", "开piao日期 >= #" & fd & "# And 开piao日期 <= #" & ld & "# And [_Identify] <> " & t1.Rows(i)("_Identify")) '取得该月的最大编号
MessageBox.Show(max)