Does record already exist?

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.
 
A

Albert D. Kallal

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
 

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