Combining Two DCount expressions in one

nmodhi

Registered User.
Local time
Today, 15:19
Joined
Jan 26, 2010
Messages
25
Hello all,

I'm trying to create two DCount expressions in one simply to check if two fields are equal to another set of two fields. For example:

abc 123
abc 321

should be okay and return nothing. However,

abc 123
abc 123

should inform the user a duplicate entry is being entered. On my main form I have a subform in which the table of these fields are sourced too.

Here's what I have so far in the before update of the textbox, I believe it's something close to this

Code:
If DCount("Field0","table","Field1=" & Me!field1 & " AND Field2= " & Me!Field2 &"") > 0 Then 
MsgBox ("Duplicate Entry")

But it doesn't seem to to work. Any help is really appreciated since I've been stuck on this for days:eek:
 
Code:
[/FONT]If DCount("[Field0]", "table", "Field1 = " & Me[COLOR=Red].[/COLOR]Field1[COLOR=Red].value[/COLOR] & " AND [Field2] = " & Me[COLOR=Red].[/COLOR]Field2[COLOR=Red].value[/COLOR] & "") > 0 Then
    Msgbox "Duplicate Entry"
End If
Notice the red bits. You should be referring to the control, not the field. You use the dot to identify a control in Me and also I've included the ".value" method to ensure it's your control. If it throws and error there then you know that you're not calling the name of the control.

Remember not to double post.;)
 
Code:
[/FONT]If DCount("[Field0]", "table", "Field1 = " & Me[COLOR=Red].[/COLOR]Field1[COLOR=Red].value[/COLOR] & " AND [Field2] = " & Me[COLOR=Red].[/COLOR]Field2[COLOR=Red].value[/COLOR] & "") > 0 Then
    Msgbox "Duplicate Entry"
End If
Notice the red bits. You should be referring to the control, not the field. You use the dot to identify a control in Me and also I've included the ".value" method to ensure it's your control. If it throws and error there then you know that you're not calling the name of the control.

Remember not to double post.;)
 
Code:
[/FONT]If DCount("[Field0]", "table", "Field1 = " & Me[COLOR=Red].[/COLOR]Field1[COLOR=Red].value[/COLOR] & " AND [Field2] = " & Me[COLOR=Red].[/COLOR]Field2[COLOR=Red].value[/COLOR] & "") > 0 Then
    Msgbox "Duplicate Entry"
End If
Notice the red bits. You should be referring to the control, not the field. You use the dot to identify a control in Me and also I've included the ".value" method to ensure it's your control. If it throws and error there then you know that you're not calling the name of the control.

Remember not to double post.;)
 

Users who are viewing this thread

Back
Top Bottom