我有3列标题已使用,添加和总计。 条件是;
已使用:允许用户输入任何正值,但将其作为负值存储在表中。
添加:允许用户输入正值并将其作为正数存储在表字段中。
总计:存储与“已使用”和“添加”关联的字段的总和。
这是我到目前为止所拥有的。 Total提交不能按预期工作。有什么想法吗?
'Add to database a new value -------------------------
Private Sub Add_AfterUpdate()
If IsNull(Add.Value) Then
Add.Value = 0
ElseIf Add.Value < 0 Then
Add1.Value = -Add.Value
ElseIf Add.Value > 0 Then
Add.Value = Add
End If
Total_AfterUpdate 'To update the Total in textbox--------------
Add_Enter 'To show 0 in the textbox--------------
End Sub
'Substract from databae field a new value from already existing value-------
Private Sub Used_AfterUpdate()
Used.Value = Used
If IsNull(Used.Value) Then
Used.Value = 0
ElseIf Used.Value < 0 Then
Used.Value = -Used.Value
ElseIf Used.Value > 0 Then
Used.Value = Used
End If
Total_AfterUpdate 'To update the Total in textbox--------------
Add_Enter 'To show 0 in the textbox--------------
End Sub
'Total the results based on changes made through the Used textbox or the Add texbox
Private Sub Total_AfterUpdate()
Dim TotalAdd As Double
Dim TotalUsed As Double
TotalAdd = Total.Value + Add
Total = TotalAdd
TotalUsed = Total.Value - Used
Total = TotalUsed
End Sub
答案 0 :(得分:1)
除非我误解,否则尝试这样的事情:
Private Sub Used_AfterUpdate()
If IsNull(Used) Then
Used = 0
ElseIf Used > 0 Then
Used = -Used
End If
Total_AfterUpdate
End Sub
Private Sub Add_AfterUpdate()
If IsNull(Add) Then
Add = 0
ElseIf Add < 0 Then
Add = -Add
End If
Total_AfterUpdate
End Sub
Private Sub Total_AfterUpdate()
Total = Used + Add
End Sub
Private Sub Used_AfterUpdate()
Used = -Abs(Nz(Used, 0))
Total_AfterUpdate
End Sub
Private Sub Add_AfterUpdate()
Add = Abs(Nz(Add, 0))
Total_AfterUpdate
End Sub
Private Sub Total_AfterUpdate()
Total = Used + Add
End Sub