textbox exit event on userform

hearthhrob4gals

Board Regular
Joined
Aug 20, 2014
Messages
142
Hi,

i create multiple textboxes with dynamic names during the run time on userform.

On any of the textbox exit, i need to do some calculation and show the output in a label corresponding to that particular text box.

however the textbox exit event is not working with the dynamic name that i have set

the normal code that works is
Code:
Private Sub Textbox1_Update(ByVal Cancel As MSForms.ReturnBoolean)
 Call doValidation(Textbox1)
End Sub

however,instead of textbox1, the dynamic textbox name is txt1. i tried replacing textbox1 with txt1. however, it didnt work.

the below code is how i created these textboxes

Code:
   Dim txtB2 As Control
    Dim h
    k = 160
    For h = 1 To Z
        Set txtB2 = Controls.Add("Forms.TextBox.1")
        With txtB2
            .Name = "txt" & h
            .Height = 20
            .Width = 50
            .Left = 240
            If h = 1 Then
            .Top = k + 30
            Else
            .Top = z1 + 30
            End If
            z1 = .Top
        End With
    Next h
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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