Help!! Syntax errors on DCount function

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Hi all,
Can you tell me what I'm getting wrong in the code below.
I'm trying to prevent duplicate values where the RowID AND
the Number are the same. eg...

RowID Number
2 2
2 15
2 19
2 28
2 32
2 48
3 2 (OK as RowID different)
3 17
3 27
3 27 (NOT ALLOWED)

Here's my code:

If DCount("[Number]", "tbl_OurLottery", "Number= '" & Me.
Number & "' And RowID = & Me.RowID") > 1 Then blah blah

The above is under the 'Before Update' event of a subform.
I hope you can help.
Thanks as always
Lee
 
Is [Number] a Number or Text data type? If it's a NUmber,
you don't need the single quotes around it.

Also, you need to move your final quotes:

If DCount("[Number]", "tbl_OurLottery", _
"Number=" & Me.Number & " And RowID=" _
& Me.RowID) > 1 Then ...

Hopr this helps!

Howard Brody
 
Hello Howard,
Thanks VERY much for such a quick response!
Initially this didn't work but that was only because I
should have set the value to >0 rather than >1. This
defies my sense of logic mind you, but it works!! I guess
it's because it's working on the BEFORE update event....
anyway, thanks again.
Kind Regards,

Lee

-----Original Message-----
Is [Number] a Number or Text data type? If it's a NUmber,
you don't need the single quotes around it.

Also, you need to move your final quotes:

If DCount("[Number]", "tbl_OurLottery", _
"Number=" & Me.Number & " And RowID=" _
& Me.RowID) > 1 Then ...

Hopr this helps!

Howard Brody

-----Original Message-----
Hi all,
Can you tell me what I'm getting wrong in the code below.
I'm trying to prevent duplicate values where the RowID AND
the Number are the same. eg...

RowID Number
2 2
2 15
2 19
2 28
2 32
2 48
3 2 (OK as RowID different)
3 17
3 27
3 27 (NOT ALLOWED)

Here's my code:

If DCount("[Number]", "tbl_OurLottery", "Number= '" & Me.
Number & "' And RowID = & Me.RowID") > 1 Then blah blah

The above is under the 'Before Update' event of a subform.
I hope you can help.
Thanks as always
Lee
.
.
 
Back
Top