Hello all,
I am using Access 2007 and have a form to enter debit and credits for a bank account. I have an unbound combo box named "Transaction" and it contains 2 options, Debit and Credit. There is also an "Amount" text box in which to enter the debit or credit amount. When the user selects Debit from the combobox, I need a validation rule to prevent the user from entering a positive number into the "Amount" field.
I inserted the following code into the form's BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Transaction= "Debit" And Len(Me.Amount) > 0 Then
Cancel = True
MsgBox "Debits must be a negative amount."
End If
End Sub
My problem is that when I select Debit from the combobox, the message appears regardless of whether I enter a positive or negative number into the "Amount" field.
I do not know what I am missing in my code to ensure that the message appears only when a positive number is entered.
Thank you for any help that you can provide!
I am using Access 2007 and have a form to enter debit and credits for a bank account. I have an unbound combo box named "Transaction" and it contains 2 options, Debit and Credit. There is also an "Amount" text box in which to enter the debit or credit amount. When the user selects Debit from the combobox, I need a validation rule to prevent the user from entering a positive number into the "Amount" field.
I inserted the following code into the form's BeforeUpdate event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Transaction= "Debit" And Len(Me.Amount) > 0 Then
Cancel = True
MsgBox "Debits must be a negative amount."
End If
End Sub
My problem is that when I select Debit from the combobox, the message appears regardless of whether I enter a positive or negative number into the "Amount" field.
I do not know what I am missing in my code to ensure that the message appears only when a positive number is entered.
Thank you for any help that you can provide!