help with this code.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using db which simillar to the sample expense reports database by
microsoft

in the expense reports subform , for the on exit event of the field
Expenseitemamount , I have this code

Private Sub ExpenseItemAmount_Exit(Cancel As Integer)
If Not Me.NewRecord Then
If ExpenseItemAmount = 0 Or IsNull(ExpenseItemAmount) Then
MsgBox "Please Enter Transaction Amount"
Cancel = True
End If
End If
End Sub

it is working ok , but some times the user bring the focus to this field for
a new record ( by mistake) i.e he doesnt want to add any more transactions
for the current expensereport, but want to add a new expense report , and
then , when he or she wanted to add a new record to the form expense reports
( the main form)(by clicking the add button in the record navigation buttons)
, it is giving error( runtime error 2424)


what should i do

the above code is for the expenseitemamount not to be left blank or zero
anyway.
 
Use the BeforeUpdate event procedure of the *form* (not control) to test if
a field was left Null:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.ExpenseItemAmount,0) = 0 Then
Cancel = True
MsgBox "Please Enter Transaction Amount"
Me.ExpenseItemAmount.SetFocus
End If
End Sub
 
Back
Top