Prevent duplication at time of entry

B

Bruce

I'm trying to prevent people from entering a duplicate Client Code.

Currently I am using the BeforeUpdate event, searching a
RecordsetClone for an existing code, and cancelling the update if a
match is found (with a message box alert).

This all works fine, but when a duplicate is found I want the text in
the Client Code textbox to be highlighted so that the user can simply
type the new code instead of having to backspace over the already
entered code.

I've tried a variety of things (setfocus, AfterUpdate, "", etc).

Any suggestions?

Bruce
 
C

Chris

Hi Bruce

I saw your post and I am trying to achieve the same thing, as you are one
step ahead of me I wondered if you would be able to help me with the code you
have so far. My original post is dated 02/12 under forms coding. My VBA
knowledge is quite limited at the moment, but I am thinking the undo property
might well be the answer. perhaps someone with more knowledge can come up
with the answer to help us both!

Regards

Chris
 
D

Dirk Goldgar

Bruce said:
I'm trying to prevent people from entering a duplicate Client Code.

Currently I am using the BeforeUpdate event, searching a
RecordsetClone for an existing code, and cancelling the update if a
match is found (with a message box alert).

This all works fine, but when a duplicate is found I want the text in
the Client Code textbox to be highlighted so that the user can simply
type the new code instead of having to backspace over the already
entered code.

I've tried a variety of things (setfocus, AfterUpdate, "", etc).

Any suggestions?

What you ask is possible, but why not just undo the user's entry?
Something along the lines of:

'----- start of example code -----
Private Sub ClientCode_BeforeUpdate(Cancel As Integer)

' ... code that determines this is a duplicate ...

If (this is a duplicate) Then
Cancel = True
Me!ClientCode.Undo
End If

End Sub
'----- end of example code -----
 
Top