View Single Post
  #3  
Old July 7th, 2009, 08:17 PM posted to microsoft.public.access
Clifford Bass[_2_]
external usenet poster
 
Posts: 1,295
Default Before-update reference on a field

Hi,

If you look at what you put in for the third parameter it will always
evaluate to true and so as long as you have any records in the table, you
will get an invoice number back from the DLookup() function; which in itself
will be interpreted as true unless it is zero. Try this instead:

If IsNull([V_InvoiceNumber]) Then
MsgBox "Please enter an invoice number."
Cancel = True
Else
If Not IsNull(DLookup("[V_InvoiceNumber]", "[VendorRecordsTable]",
"[V_InvoiceNumber] = " & [V_Invoice_Number])) Then
If MsgBox("Invoice number already exists. Continue?", vbYesNo, _
"Invoice Number Duplicate") = vbNo Then
Cancel = True
End If
End If
End If

Clifford Bass

"Pwyd" wrote:

Private Sub V_InvoiceNumber_BeforeUpdate(Cancel As Integer)

If DLookup("[V_InvoiceNumber]", "[VendorRecordsTable]", "Not
IsNull([V_InvoiceNumber]=[Forms]![Main Record]![V_InvoiceNumber]) ") Then
If MsgBox("Invoice number already exists. Continue?", vbYesNo, _
"Invoice Number Duplicate") = vbNo Then
Cancel = True
End If
End If

End Sub


this is currently sitting in the "before update" field, happily provided to
me by some other access database helpers here in the community. However
after testing it, it ALWAYS asks whether i want to cancel, regardless of
wehther the invoice number is actually a duplicate. I've read the reference
on IsNull and what it resolves to, and i'm not sure wehther this is what i
want, however i'm not sure what i should replace it with. Nz() perhaps? i
was only trying to prevent it from trying to do a comparison of "null" to a
string "null" which i'm told is invalid.