T
Tony Williams
I am trying to write code that checks the input in controls on a form and if
they are incorrect to show a message.Here is my code which I have in the
Before Update Event of the form
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Cash_Price As Integer
Dim Deposit As Integer
Dim Amount_of_Credit As Integer
Dim Charges As Integer
Dim Initial_Balance_Outstanding As Integer
Dim Payments_Made As Integer
Dim Current_Balance_Outstanding As Integer
Dim strMessage As String
If Cash_Price - Deposit <> Amount_of_Credit Then
strMessage = strMessage & "The Amount of Credit " & _
"does not equal the Cash Price less Deposit" & vbCrLf & _
"It should be " & Amount_of_Credit
End If
If Len(strMessage) > 0 Then
If MsgBox(strMessage & " - Do you want to accept the error(s)?", _
vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If
End Sub
Firstly I realise I have problems with the control names having spaces but I
have inherited this database.
The code at the moment includes other controls that I want to check but I am
trying to get the first one right. The user will input the Cash Price,
Deposit and Amount of Credit from a paper form. I want the code to check
that the Amount of Credit = Cash Price Less Deposit and if it doesn't show a
message asking the user whether or not to accept the error.
This code doesn't work although I have compiled it and there are no errors.
Anyone help?
Thanks
Tony
they are incorrect to show a message.Here is my code which I have in the
Before Update Event of the form
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Cash_Price As Integer
Dim Deposit As Integer
Dim Amount_of_Credit As Integer
Dim Charges As Integer
Dim Initial_Balance_Outstanding As Integer
Dim Payments_Made As Integer
Dim Current_Balance_Outstanding As Integer
Dim strMessage As String
If Cash_Price - Deposit <> Amount_of_Credit Then
strMessage = strMessage & "The Amount of Credit " & _
"does not equal the Cash Price less Deposit" & vbCrLf & _
"It should be " & Amount_of_Credit
End If
If Len(strMessage) > 0 Then
If MsgBox(strMessage & " - Do you want to accept the error(s)?", _
vbYesNo, "Calculation Error") = vbNo Then
Cancel = True
End If
End If
End Sub
Firstly I realise I have problems with the control names having spaces but I
have inherited this database.
The code at the moment includes other controls that I want to check but I am
trying to get the first one right. The user will input the Cash Price,
Deposit and Amount of Credit from a paper form. I want the code to check
that the Amount of Credit = Cash Price Less Deposit and if it doesn't show a
message asking the user whether or not to accept the error.
This code doesn't work although I have compiled it and there are no errors.
Anyone help?
Thanks
Tony