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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Alan

Is your tbPPCode a TextBox.

Have you tried

Private Sub TextBox1_Exit

ColinKJ
 
Upvote 0
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,215,233
Messages
6,123,771
Members
449,122
Latest member
sampak88

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