Private Sub btnFentan_Click() '分摊付款金额,进货_退货
On Error GoTo ErrorHandler
Dim cnn As Object
Dim rstTmp As Object
Dim blnTransBegin As Boolean
Dim AMT_X As Currency
If Me![AMT].Value < 0 Or Me![AMT] = "" Or Me![BANK] = "" Then
Exit Sub
End If
Set cnn = CurrentProject.Connection
cnn.BeginTrans: blnTransBegin = True
'主窗体金额控件传递给变量 AMT_X
Set rstTmp = CurrentDb.OpenRecordset("select * from TMP_FK_TF order by sfgx*amt desc")
AMT_X = Eval(Me![AMT])
Do Until rstTmp.EOF
rstTmp.Edit
If rstTmp![SFGX] = -1 Then '应付时
If rstTmp![AMT] - rstTmp![AMT_FI] <= AMT_X Then 'abs (未付金额) <= AMT_X
rstTmp![AMT_NOW] = rstTmp![AMT] - rstTmp![AMT_FI] '现付金额= abs (未付金额)
Else: rstTmp![AMT_NOW] = AMT_X '否则 现付金额= AMT_X
End If
AMT_X = AMT_X - rstTmp![AMT_NOW] '剩余金额
Else
rstTmp![AMT_NOW] = rstTmp![AMT] - rstTmp![AMT_FI] '现付金额= abs (未付金额)
AMT_X = AMT_X + rstTmp![AMT_NOW] '剩余金额
End If
rstTmp.Update
rstTmp.MoveNext
Loop
rstTmp.Close
Set rstTmp = Nothing
cnn.CommitTrans: blnTransBegin = False
Me.sfrDetail.Requery
ExitHere:
rstTmp.Close
Set rstTmp = Nothing
Set cnn = Nothing
Exit Sub
ErrorHandler:
If blnTransBegin Then
cnn.RollbackTrans
blnTransBegin = False
End If
MsgBoxEx Err.Description, vbCritical
RDPErrorHandler Me.Name & ": Sub btnFentan_Click()"
Resume ExitHere
End Sub