This is a tough one! Spent all day on it. I am creating a VBA userform with a couple controls at run time. Everything works fine, but I CANNOT get the controls to reflect changes, as in:
Textbox1.Text = "old"
gets updated to
Textbox1.Text = "new"
Graphically, the control still says "old", but if I do a debug.print the value returned is "new". It's like somehow I need to force a refresh or paint or something (I already tried userform.repaint)
Would appreciate any thoughts on this. All code is run from a VBA Module and uses the MSForms.Dll reference:
That's the simple version of the code. Now try changing the caption of Label1:
NewForm.Label1.Caption = "test"
I've also tried: NewForm!Label1.Caption too
The ONLY way I could get the caption to physically change was to put this line of code above the VBA.UserForms...Show line at the end of my code. Putting the code anywhere else, in the Module, in the UserForm Module (as it's own Sub and tried in an Event procedure), has no visual effect (though again, if you debug.print the value really is changing)
My last idea is to try to hide and unhide the entire form, hoping that would force a refresh, but I'm getting some modal window errors I haven't quite worked through yet.
Has anyone ran across this??
Textbox1.Text = "old"
gets updated to
Textbox1.Text = "new"
Graphically, the control still says "old", but if I do a debug.print the value returned is "new". It's like somehow I need to force a refresh or paint or something (I already tried userform.repaint)
Would appreciate any thoughts on this. All code is run from a VBA Module and uses the MSForms.Dll reference:
Code:
Private Sub LoadMultiForm()
Dim TempForm 'As VBComponent
Dim Lbl1 As MSForms.Label
' Hide VBE window to prevent screen flashing
Application.VBE.MainWindow.Visible = False
' Create the UserForm
Set TempForm = Application.VBE.ActiveVBProject.VBComponents.Add(3)
With TempForm
.Properties("Height") = 303
.Properties("Width") = 651
.Properties("Name") = "NewForm"
.Properties("Caption") = "Update Table Links"
End With
'add header labels
Set Lbl1 = TempForm.Designer.Controls.Add("Forms.Label.1")
With Lbl1
.Left = 6
.Top = 34
.Height = 18
.Width = 126
.BorderStyle = fmBorderStyleSingle
.Caption = " Local Table"
End With
...
...
..
' Show the form
VBA.UserForms.Add(TempForm.Name).Show
That's the simple version of the code. Now try changing the caption of Label1:
NewForm.Label1.Caption = "test"
I've also tried: NewForm!Label1.Caption too
The ONLY way I could get the caption to physically change was to put this line of code above the VBA.UserForms...Show line at the end of my code. Putting the code anywhere else, in the Module, in the UserForm Module (as it's own Sub and tried in an Event procedure), has no visual effect (though again, if you debug.print the value really is changing)
My last idea is to try to hide and unhide the entire form, hoping that would force a refresh, but I'm getting some modal window errors I haven't quite worked through yet.
Has anyone ran across this??