Trying to cancel texbox entry if duplicate (1 Viewer)

Malcy

Registered User.
Local time
Today, 10:40
Joined
Mar 25, 2003
Messages
586
Hi
I have one that is doing my head in.
I need to test that a Job Number has not been used before. If it has there is a very slight chance they might want to re-use it. The relevant bit of my code (in the BeforeUpdate event) is
Code:
' Verify if job number has already been used
    varJob = DLookup("lngJob", "tblJobs", "[strJobNo] = '" & Me.txtJobNo & "'")
    
' If job number has been already used check with user
    If Not IsNull(varJob) Then
       
' Advise user
        varResponse = MsgBox("This job number has already been used." & vbLf & vbLf & "Are you sure you want to re-use it?", vbYesNo, "Duplicate job number - Confirmation required")
        
        If varResponse = vbNo Then
            
            Cancel = True
            Undo

        End If
    End If
[\CODE]

When I run it and deliberately use a duplicated number it picks it up and gives me the message. When I say no it retains the entered number with the cursor flashing at the end of the number. I want it to remove the entered number and mae it clear another number needs to be entered.
What is it I am missing? It has been a long weekend so I guess I may kick myself when someone is able to point out the obvious :-)
Thanks for any input
 

SOS

Registered Lunatic
Local time
Today, 02:40
Joined
Aug 27, 2008
Messages
3,514
Change it to

Me.YourControlName.Undo

or if you want the whole form reset

Me.Undo
 

Malcy

Registered User.
Local time
Today, 10:40
Joined
Mar 25, 2003
Messages
586
Thanks
That sort of three quarters did the trick in that it throws the focus back onto the textbox and allows everything to be written over.
Ideally I would also like it to null off the previous entry so the new entry is "fresh" rather than just highlighting it so as to enable overwriting. I will try tinkering further.
Thanks for the help
Best wishes
 

Users who are viewing this thread

Top Bottom