Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preemptive primary key check

Status
Not open for further replies.

aperture

Programmer
Jul 25, 2001
22
US
hello all,

i have a form which contains several required fields. the first of these is the first in the form's tab order, and its control source is the underlying table's primary key.

i would like to check whether the value entered will produce a duplicate in the primary key BEFORE the user enters the rest of the record, and saves it. is there a bit of code i can use the On Exit event to accomplish this?

thanks,

ap
 
here is one of many ways. I would put in the before update event

obviously needs some work but you get the idea.

if dcount("keyfiledname","tablename", "primary key =" me.fieldname) >=1 then
msgbox "key already exists"
me.undo
'what ever else you want
end sub
 
Hi gol4,

I am trying avoid duplicate entries as aperture is doing; however, my case is more complicated. since my primary key is a composite key. For this reason, I have to match more than 1 fields. Can you please help? Thank you so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top