Help with DCOUNT Function

JungleJme

Registered User.
Local time
Today, 03:57
Joined
Jun 18, 2012
Messages
38
Hi,

I've got a form that sits on the top of a table (company_table). Will (eventually) allow the user to add a new company to the table by entering a text name in the control Company_Name.

I'm to put a bit of logic together that will stop duplicate records being created. I thought i would use DCount for this but the following statement always evaluates to true (i.e. the message box always comes up) no matter what i enter in the Me.Company_Name field.

Any help on where i am going wrong?

Code:
If DCount("[company_name]", "company_table", Me.Company_Name) > 0 Then
MsgBox "This Company Already Exists!"
End If

Thanks

J
 
Try this :
If DCount("[company_name]", "company_table", "[company_name]=" & "'" & Me.Company_Name & "'") > 0 Then MsgBox "This Company Already Exists!" End If
 
Try this:
DCount("company_name", "company_table", "company_name = " & Me.Company_Name)

But is better to define an index unique on field company_name at table level
 

Users who are viewing this thread

Back
Top Bottom