code that can tell reuse of primary key value

G

Guest

dear sir,
i would like to have one such qery and code that can tell me the re use of
primary key valuue and when it was used like for example
table 1
field [employee] text
" [employee id] number(pk)
" [enrolment date] date
now i wnt an qury and code on the form before up date event
that can tell the.msgbox( (1) the primary key value [123] & was alloted to
[abc ] employee] &
on [enrolment date ] &" can't be used again "
cancel = true
how to do this please?
 
B

Baz

If this is important to you then the BeforeUpdate event is the wrong place
to do it. If you use BeforeUpdate to test for PK duplication, then there
remains the possibility that, after a successful test, another user could
save a new record BEFORE your record actually gets saved.

To make this foolproof you should code the form's Error event to trap the
error:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 3022 Then
MsgBox "Duplicate primary key"
Response = acDataErrContinue
Else
Response = acDataErrDisplay
End If

End Sub
 

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