User forms _Change()

AlanAnderson

Board Regular
Joined
Jun 7, 2010
Messages
134
Hi,
I have a little routine that is supposed to test that duplication does not occur. Problem is that if I use tbPPCode_Click the user may bypass it by using tab keys. If I use tbPPCode_Change the event triggers on the second key pressed. How can I force this routine to wait untill the client moves on to the next field

Thanks,

Alan
Code:
Private Sub tbPPCode_Change()
Dim PPCode As String
Dim FinalRowPricePoint As Long
FinalRowPricePoint = Cells(Rows.Count, 1).End(xlUp)
Sheets("PricePricePoint").Select
    For i = 2 To FinalRowPricePoint
        If Me.tbPPCode = Cells(i, 1) Then
            MsgBox "You may not enter duplicate codes"
            Me.tbPPCode = ""
        End If
    Next i
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Colin, Thanks for reply. I just tried that and get "Compile Error: Procedure declaration does not match description of event or procedure having the same name"

tbPPCode is a text box within a user form. BTW I'm using 2003 - maybe that makes a difference.

Thanks,

Alan
 
Upvote 0
The full declaration is:
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

To get this, select Textbox1 from the left dropdown at the top of the main code window, then select Exit from the right-hand dropdown.
 
Upvote 0
Alan,

You will need to use the Exit for your TextBox tbPPCode.

You will need to go into your code, and first select your tbPPCode from the top lefthand dropdown, then, from the top righthand dropdown, select Exit.

You should get a private sub something like

Code:
Private Sub tbPPCode_Exit(ByVal Cancel As MSForms.ReturnBoolean)

ColinKJ
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top