![]() |
Problem setting text on a userform's "label"
I have a Userform that contains a Label form and here is
the initialize code: -------------------------------------------- Private Sub UserForm_Initialize() |
Problem setting text on a userform's "label"
Your code worked perfectly for me (xl2003).
Although, I would have used this SetMyLabel procedure instead: Public Sub SetMyLabel() Dim s1 As String, s2 As String s1 = "Hello " s2 = "World!" Me.Label1.Caption = s1 & s2 ' This code has no effect End Sub I put this code inside the userform module (not in a general module). The Me keyword refers to the object owning the code--and I don't have to worry about the name of the userform being renamed. Maybe, that's the problem. The userform that's being initialized isn't named Userform1. And you're really changing the label on the wrong userform. ps. Dim s1, s2 as string declares s2 as a string, but s1 is declared as a variant. Robert Crandal wrote: I have a Userform that contains a Label form and here is the initialize code: -------------------------------------------- Private Sub UserForm_Initialize() . . Call SetMyLabel ' procedure call End Sub ---------------------------------------------- Public Sub SetMyLabel() Dim s1, s2 as String s1 = "Hello " s2 = "World!" UserForm1.Label1.Caption = s1 & s2 ' This code has no effect End Sub ----------------------------------------------- So, when this code runs, my label ends up being blank. Is it because the "SetMyLabel" procedure and all its local variables get deallocated after the procedure runs, so therefore the text on the label remains blank?? How can i fix this?? thank u -- Dave Peterson |
All times are GMT +1. The time now is 09:55 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com