RE: Prevent duplicate record through form.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The first problem is "" is not the same as Null. I think you may want to try
this:
Dlookup returns a Null vaule if it does not find a match.

If IsNull(DLookup("Cert_ID", "Accounts", "[Cert_ID]= " _
& [forms]![Account![Cert_ID]) Then
' It is a new value for this field
MsgBox "Looks Good"
Else: MsgBox"Record Already exists!"
Cancel = True
End If


"Randy" wrote:

> I have seen this question many times, but I cant get it to work. I have a
> tble named "Accounts" with a fld of "Cert_ID". The field "Cert_ID" will
> have some null values, but what ever data is there can not be duplicated.
> This is a text field. The forms name is "Account" and the textbox name is
> "Cert_ID" with the record source of "Cert_ID" I have seen an several
> examples of preventing duplicates such as below but cant get it to work.
> Any help is appreciated...Thanks..Randy
>
> If Not IsNull(DLookup("Cert_ID", "Accounts", _
> "[Cert_ID]=" & "'" &
> Me.Cert_ID & "'")) _
> Then
> MsgBox "Record Already exists!"
> ' Cancel = True
> Else: MsgBox "Looks Good"
> End If
>
>
>
.



Relevant Pages

  • Re: Prevent duplicate record through form.
    ... > The first problem is "" is not the same as Null. ... >> examples of preventing duplicates such as below but cant get it to work. ... >> ' Cancel = True ...
    (microsoft.public.access.forms)
  • RE: Force input in multiple cells in Excel form
    ... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) ... MsgBox ... MsgBox ("You must enter a value for 'Contract Type'") ...
    (microsoft.public.excel.programming)
  • RE: Force input in multiple cells in Excel form
    ... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) ... MsgBox ... MsgBox ("You must enter a value for 'Contract Type'") ...
    (microsoft.public.excel.programming)
  • RE: Force input in multiple cells in Excel form
    ... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) ... myArray= "Contract Document Type" ... MsgBox "Please enter a " & myArray, ...
    (microsoft.public.excel.programming)
  • RE: Force input in multiple cells in Excel form
    ... MsgBox ... Private Sub Worksheet_SelectionChange1 ... MsgBox ("You must enter a value for 'Contract Type'") ... Private Sub Contract_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) ...
    (microsoft.public.excel.programming)