help with this code.

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.
 
A

Allen Browne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top