Does record already exist?

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

Guest

I have a form that display records in a table. The only field displayed is
City. I also have a text box and an ADD button where users can enter a City
and add a record to the table.

What VBA code can I run to first check whether or not the entered City
already exists in the table?

Thanks.
 
if you place a unique index on the table then you don't have to write any
code and all.

however you can place the following code in the before update event of the
record.


if dcount("*","tblCities","City = '" & me!City & "'") > 0 then
cancel = true
msgbox "city is already in table"
end if
 
Back
Top