Checking for Duplicate

  • Thread starter RedHeadedMonster via AccessMonster.com
  • Start date
R

RedHeadedMonster via AccessMonster.com

I have the following code on the BeforeUpdate Event of a control:

If DCount("[ODUSerial]", "RAdioInfo", "[ODUSerial] =' " & Me.ODUSerial.Value
& "'") > 0 Then
MsgBox "This Serial Number " & Me.ODUSerial.Value _
& " has already been used!", vbExclamation, "Duplicate Serial #"
End If

I put in what I know to be a duplicate value, and NOTHING happens. What am I
not seeing?

RHM
 
D

Damon Heron

Try:
If DCount("[ODUSerial]", "RAdioInfo", "[ODUSerial] = " & " ' " &
Me.ODUSerial.Value & " ' ") > 0 Then


Damon
 
D

Dirk Goldgar

RedHeadedMonster via AccessMonster.com said:
I have the following code on the BeforeUpdate Event of a control:

If DCount("[ODUSerial]", "RAdioInfo", "[ODUSerial] =' " &
Me.ODUSerial.Value
& "'") > 0 Then
MsgBox "This Serial Number " & Me.ODUSerial.Value _
& " has already been used!", vbExclamation, "Duplicate Serial #"
End If

I put in what I know to be a duplicate value, and NOTHING happens. What
am I
not seeing?


The value you are building into the criteria string for comparison will have
a leading space, the way you have it. Try this:

If DCount("ODUSerial", "RAdioInfo", _
"ODUSerial = '" & Me.ODUSerial & "'") _
Then


Note: You don't need the square brackets around ODUSerial, so I took them
out.
 
R

RedHeadedMonster via AccessMonster.com

Thanx hon, worked like a charm!
Have a nice Day!
RHM

Dirk said:
I have the following code on the BeforeUpdate Event of a control:
[quoted text clipped - 8 lines]
am I
not seeing?

The value you are building into the criteria string for comparison will have
a leading space, the way you have it. Try this:

If DCount("ODUSerial", "RAdioInfo", _
"ODUSerial = '" & Me.ODUSerial & "'") _
Then

Note: You don't need the square brackets around ODUSerial, so I took them
out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top