TextBox Change in a Dynamic Control Array

TedSki

Board Regular
Joined
Apr 17, 2008
Messages
63
I have search everywhere for this one but still have found nothing to help.
I am using Visual Basic 6.5
I have a formula in an Excel cell ("=100+200+300+400") which I split out into the values (100,200,300,400). Using a loop I create four textboxes dynamically and then display userform. When I change the value of TextBox0, nothing happens. I have tried TextBox0_Change, TextBox0_AfterUpdate, TextBox0_Click, TextBox0_LostFocus. I placed message boxes in each to see which one works and none of them do. The following is the code that creates the textboxes:

Public Sub UserForm_Initialize()
Set X = CreateObject("Scripting.Dictionary")
Dim s As String
Dim p As String
Dim tname As String
Dim SLen As Integer
Dim XI As Integer
Dim I As Long
Dim J As Long
Dim UppB As Long
Dim SWdth As Long
Dim STotal As Currency
Dim MyControl As Control
XI = 80
STotal = 0

getformula = ThisWorkbook.Sheets(1).Range("A1").Formula
'
s = getformula
SLen = Len(s)
p = Mid(s, 2, SLen)

X = Split(p, "+")

If UBound(X) < 0 Then
UppB = 0
Else
UppB = UBound(X)
End If

For I = LBound(X) To UppB
tname = "TextBox" & I

Set TempValue = UserForm1.Controls.Add("Forms.TextBox.1", tname)
With UserForm1.Controls.Item(tname)
.Top = 50
.Width = 70
.FontName = "Times New Roman"
.FontSize = 12
If UBound(X) < 0 Then
.Left = 50
.Value = 0
Else
.Left = XI
.Value = X(I)
End If
.Text = Format(TempValue.Value, "$#,##0.00") '
End With
STotal = STotal + TempValue.Text
MsgBox (UserForm1.Controls.Item(tname).Name)
Next I
SWdth = XI + 50
UserForm1.Width = SWdth
End Sub

The MsgBox displays "TextBox0", "TextBox1", "TextBox2", "TextBox3"

These are my events when I change TextBox0 from 100 to 50.

Private Sub TextBox0_KeyPress(Index As Integer, KeyAscii As Integer)
MsgBox ("User has typed something into the " & Textbox0(Index).Name & " TextBox")
End Sub

Private Sub TextBox0_Click()
Dim VTotal As Currency
Dim STotal As Currency

MsgBox ("TextBox0 click")
VTotal = Textbox0.Value
Textbox0.Value = Format(VTotal, "$#,##0.00")
End Sub

Private Sub TextBox0_LostFocus()
Dim VTotal As Currency
Dim STotal As Currency

MsgBox ("TextBox0 lost focus")
VTotal = Textbox0.Value
Textbox0.Value = Format(VTotal, "$#,##0.00")
End Sub

Private Sub TextBox0_Change()
Dim VTotal As Currency
Dim STotal As Currency

MsgBox ("TextBox0 changed")
VTotal = Textbox0.Value
Textbox0.Value = Format(VTotal, "$#,##0.00")
End Sub

Private Sub TextBox0_AfterUpdate()
Dim VTotal As Currency
Dim STotal As Currency

MsgBox ("TextBox0 after update")
VTotal = Textbox0.Value
Textbox0.Value = Format(VTotal, "$#,##0.00")
End Sub

Can anyone help or at least tell me where I can find help?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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