Why wont this simple code work!

B

Bob

All I want is the record not to save unless there is data in Both, cbOwnerID
and TbAmountpaid
Private Sub cmdClose_Click()
If IsNull(cbOwnerID) And (TbAmountPaid) Then
If Me.Dirty Then
Me.Undo
End If
End If

DoCmd.Close acForm, Me.Name

End Sub
 
D

David F Cox

If I am seeing this right (I should be in bed) it should be :
IsNull(cbOwnerID) OR IsNull (TbAmountPaid) then
' data not present in both fields
....
Else
 
K

Ken Snell \(MVP\)

What happens when you use this code? If it is "failing", are you sure that
your form's data have not already been saved before the code runs (such that
Me.Dirty is False)?
 
B

Bob

David using your code nothing is saving, not even if i have data in both
fields
Funny thing is I can get either one to work but not together, here they are
seperate that do work:
Thanks for any help.................Bob
-------------------------------------------------------------------------------
Private Sub cmdClose_Click()
If IsNull(cbOwnerID) Then
If Me.Dirty Then
Me.Undo

End If

DoCmd.Close acForm, Me.Name
End If
End Sub
-----------------------------------------------------------------------------------
Private Sub cmdClose_Click()
If IsNull(tbPaidAmount) Then
If Me.Dirty Then
Me.Undo

End If

DoCmd.Close acForm, Me.Name
End If
End Sub
-------------------------------------------------------------------------------------------
 
B

Bob

Oops 2 different DBs !!

Bob said:
David using your code nothing is saving, not even if i have data in both
fields
Funny thing is I can get either one to work but not together, here they
are seperate that do work:
Thanks for any help.................Bob
-------------------------------------------------------------------------------
Private Sub cmdClose_Click()
If IsNull(cbOwnerID) Then
If Me.Dirty Then
Me.Undo

End If

DoCmd.Close acForm, Me.Name
End If
End Sub
-----------------------------------------------------------------------------------
Private Sub cmdClose_Click()
If IsNull(tbPaidAmount) Then
If Me.Dirty Then
Me.Undo

End If

DoCmd.Close acForm, Me.Name
End If
End Sub
 
J

JK

Bob,

In the table(s), for each of the fields properties

Required=Yes
Validation Rule: <>0
Validation Text: (the message you want to see when the rule is violated)


Make sure that all the records already in table conform with this rule
before you make these changes

Regards
Jacob
 

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