.....
if me.金额.value>999999.99 then
x=me.金额.value
y=me.数量.value
j=int(me.金额.value/999999.99)
for i=1 to j+1
rs.addnew
rs("单号")=me.单号.value
rs("名称描述")=me.名称描述.value
rs("单位")=me.单位.value
rs("客户材料")=me.客户材料.value
if i<=j then
rs("数量")=me.数量.value * 999999.99 / me.金额.value
rs("金额")=999999.99
else
rs("数量")=y
rs("金额")=x
end if
rs.Update
x = x - rs("金额")
y = y - rs("数量")
next
end if
....作者: rainless_9 时间: 2009-5-25 22:22
如果要同时拆分一个订单多行>100W的 or 多个订单多行>100W 改如何操作?
Private Sub 拆分_Click()
Dim rs As New ADODB.Recordset
Dim sql1 As String, sql2 As String
Dim i As Long, m As Long, n As Long
Dim x As Double, y As Double, Q As Double, r As Double
Q = 999999.99
sql1 = "select * from 订单明细 where 单号='" & Me.单号.Value & "'"
rs.Open sql1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
sql2 = "DELETE * FROM 临时表"
CurrentDb.Execute sql2
For i = 1 To rs.RecordCount
If rs("金额") > Q Then
m = Int(rs("金额") / Q)
r = Round(rs("金额") / (m + 1), 2)
x = rs("数量")
y = rs("金额")
For n = 1 To m
sql2 = "INSERT INTO 临时表 ( 单号, 名称, 单位, 数量, 金额 ) "
sql2 = sql2 & "VALUES ('" & rs("单号") & "','" & rs("名称") & "','" & rs("单位") & "'," & Round(rs("数量") * r / rs("金额"), 0) & "," & r & ")"
CurrentDb.Execute sql2
x = x - Round(rs("数量") * r / rs("金额"), 0)
y = y - r
Next
sql2 = "INSERT INTO 临时表 ( 单号, 名称, 单位, 数量, 金额 ) "
sql2 = sql2 & "VALUES ('" & rs("单号") & "','" & rs("名称") & "','" & rs("单位") & "'," & x & "," & y & ")"
CurrentDb.Execute sql2
Else
sql2 = "INSERT INTO 临时表 ( 单号, 名称, 单位, 数量, 金额 ) "
sql2 = sql2 & "VALUES ('" & rs("单号") & "','" & rs("名称") & "','" & rs("单位") & "'," & rs("数量") & "," & rs("金额") & ")"
CurrentDb.Execute sql2
End If
rs.MoveNext
Next
Me.临时子窗体.Form.Requery
rs.Close
End Sub作者: 朱同学 时间: 2009-5-26 20:36
非常有趣,让我下了学学。作者: rainless_9 时间: 2009-5-26 22:22
能不用窗体显示吗,最好直接拆分表中的数据到新表,因为并不需要点击后一个一个单号的拆!作者: todaynew 时间: 2009-5-27 05:54 本帖最后由 todaynew 于 2009-5-27 21:14 编辑
Private Sub 拆分_Click()
.....
.....
Q = 999999.99
sql2 = "DELETE * FROM 临时表"
CurrentDb.Execute sql2
DoCmd.GoToRecord acDataForm, "主窗体", acFirst
Do While Me.单号.Value <> ""
sql1 = "select * from 订单明细 where 单号='" & Me.单号.Value & "'"
rs.Open sql1, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 1 To rs.RecordCount
......
......
Next
rs.Close
DoCmd.GoToRecord acDataForm, "主窗体", acNext
Loop
Me.Form.Requery
End Sub