comparing value of field to existing values in table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to see if a calculated value in a text field on a form is a duplicate
to existing entries in a table. I have an idea how to do it and I can search
for code examples but I do not even know what VB or SQL terms to search for.

Can you please point me in the right direction?
 
Use the code

If DCount("*","Table","FieldName = " & CalcValue) > 0 then
Msgbox "Calculated Value is NOT Unique"
else
MsgBox "Calculated Value is Unique"
end if
 
I am getting a syntax error. I have
If DCount("*", "tbl_MainTable", "LicenseNumber = " & CalcValue) > 0 Then

.... The error says: operator missing in 'LicenseNumber ='.
 
If LicenseNumber is a Text Field then you will need
If DCount("*","tbl_MainTable","LicenseNumber = '" & CStr(CalcValue) & "'") > 0
 
Thank you Dennis, that helped.

However, I'm not quite sure I understand how this works. I want to compare a
constant value "ln" in my code block to the a value in the text field in my
table. I'm not seeing how the code you supplied is doing that. The "*"
portion is screwing me up. I thought I could just use ln instead of "8".
 
Dennis,

Nevermind. I think I got it. I used CStr(ln) instead... at least it seemed
to work
 
You can. The "*" just means count the total number of records. You can
substitue the "*" for one of the Field Names in your table if that makes it
easier for you to understand when you come back to it later.
DCount("In","tbl_MainTable","LicenseNumber = '" & CStr(CalcValue) & "'")
 
Back
Top