|
Private Sub 本次收货_AfterUpdate()
On Error GoTo Err_本次收货_AfterUpdate
Dim x As Integer
Dim y As Long
If Me.本次收货 = 0 Then Exit Sub
x = Me.收货数量 + Me.本次收货
If x > Me.订单数量 Then
MsgBox "收货数量合计已超过本单订货数量。请重新输入。", vbCritical, "提示"
Me.本次收货 = 0
x = 0
Me.订单数量.SetFocus
Me.本次收货.SetFocus
Exit Sub
End If
If x = Me.订单数量 Then
Me.收货数量 = x
Me.本次收货 = 0
Me.收货数量.SetFocus
Me.本次收货.Enabled = False
Else
y = MsgBox("收货数量小于本单订货数量,是否确定属于分批收货?", vbYesNo + vbQuestion, "提示")
If y = vbNo Then
Me.本次收货 = 0
Me.订单数量.SetFocus
Me.本次收货.SetFocus
x = 0
Exit Sub
Else
Me.收货数量 = x
Me.本次收货 = 0
End If
End If
'记入STOCK表(如果表中已有此零件号则更新,没有则追加.其实按你表间约束关系,主表不可能无此零件号记录,所以只有更新语句即可了)
If IsNull(DLookup("零件号", "STOCK", "零件号 = '" & Me.零件号 & "'")) Then
DoCmd.RunSQL "INSERT INTO STOCK(零件号,描述,库存数量) VALUES('" & Me.零件号 & "', '" & Me.描述 & "', " & Me.收货数量 & ")"
MsgBox "插入OK"
Else
DoCmd.RunSQL "UPDATE STOCK SET STOCK.库存数量 = " & Me.收货数量 & " WHERE STOCK.零件号 = '" & Me.零件号 & "'"
MsgBox "更新OK"
End If
Exit_本次收货_AfterUpdate:
Exit Sub
Err_本次收货_AfterUpdate:
Resume Exit_本次收货_AfterUpdate
End Sub |
|