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?
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?