Not executing a IsNull scenario when writing a new record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #16
    I wouldn't even entertain the idea that it was done for any reason other than your temporarily losing the plot in an inattentive moment. This happens to us all from time-to-time.

    I would just offer an alternative for your first line. Some don't like using the Nz() function, but otherwise it's a more compact version.
    Code:
    If Nz(Me.ProductIDFK, 0) = 0 Then

    Comment

    • kcdoell
      New Member
      • Dec 2007
      • 230

      #17
      Originally posted by ADezii
      Here is a stretch! Since [ProductIDFK] is a LONG INTEGER Field bound to [ProductID], by Default (unless otherwise changed by you), it will have a Default Value of 0 for any given New Record and will pass the IsNull() validation. Either check the Default Value Property of the [ProductIDFK] Field to make sure it is not set to 0, or add the following Validation Code:
      [CODE=vb]
      If IsNull(Me![ProductIDFK]) Or Me![ProductIDFK] = 0 Then
      Msgbox "Missing Blah, Blah, Blah..."
      Cancel = True
      Exit Sub
      ...[/CODE]

      Let me know how you make out.
      The reason why it was happening makes complete sense to me now. In fact, Yesterday I said to myself that that somehow the DB did believe that there was a value being slected in [ProductIDFK]; it was the only thing that made sense to why it was happening.

      Both solutions solved the problem.

      Thanks a lot!!!

      Keith.

      Comment

      Working...