Peter wrote:
[color=blue]
> Can anyone advise me what is wrong with this code? I want it to tell me if
> I am entering a duplicate record.[/color]
Why don't you just take the field in question and put an index on it
with no duplicates permitted? YOu can then trap the error which would
be, I think, 3022. In the on error event of your form, do this:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 3022 'duplicate value in index/PK
MsgBox "You're an idiot, you've already entered this " & _
"registration number!", vbExclamation, "Twit!"
Response = acDataErrContinue
Case Else
Response = acDataErrDisplay 'shows normal error message
End Select
End Sub
It truly is the least worrisome approach to have as much of your data
constraints as possible as part of your table design (in this case,
indexing the registration number). If you have to depend a lot on code
in your forms to constrain your data, you will have loops holes and
bugs, plus anyone who, for whatever reason, may have to enter data
directly to the tables (perhaps you, as the system administrator) is
bound to forget about form based constraints eventually and end up with
bad data. With constraints on your tables, the limitations are
fundamental to your design.
Thus Spake E.F.Codd
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me