Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
I am using a class I found here that works very well for my needs. Now
I would like to reference and change the caption of a label of the same name (number) as the text box. The Class: Public WithEvents txtBox As MSForms.TextBox, CtlNum As String Public laBl As String Private Sub Class_Terminate() Set txtBox = Nothing End Sub Private Sub txtBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 46, 48 To 57 If Right(txtBox, 2) = ".5" Then KeyAscii = 0 If KeyAscii = 46 Then SendKeys ("5") ''' These are all number. No Problem Case Else ''' Some other kind of character. Beep and cancel it. Beep KeyAscii = 0 End Select SetLabel End Sub Private Sub txtBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 8 Then txtBox.Value = "" End Sub Private Sub txtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Len(txtBox.Text) = 3 And Right(txtBox.Text, 2) < ".5" Then txtBox = Null If Len(txtBox.Text) 4 Then txtBox = Null End Sub 'Here's where it fails. Sub SetLabel() 'This returns the TextBox number CtlNum = Mid(txtBox.Name, 8, Len(txtBox.Name)) laBl = "Label" & 3 MsgBox UserForm.Name.laBl.Caption End Sub All help will be appreciated. Thank you. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
Your routine "SetLabel" doesn't make any sense, what do you want it to do.
Regards, Peter T "Stephen Newman" wrote in message ... I am using a class I found here that works very well for my needs. Now I would like to reference and change the caption of a label of the same name (number) as the text box. The Class: Public WithEvents txtBox As MSForms.TextBox, CtlNum As String Public laBl As String Private Sub Class_Terminate() Set txtBox = Nothing End Sub Private Sub txtBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 46, 48 To 57 If Right(txtBox, 2) = ".5" Then KeyAscii = 0 If KeyAscii = 46 Then SendKeys ("5") ''' These are all number. No Problem Case Else ''' Some other kind of character. Beep and cancel it. Beep KeyAscii = 0 End Select SetLabel End Sub Private Sub txtBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 8 Then txtBox.Value = "" End Sub Private Sub txtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Len(txtBox.Text) = 3 And Right(txtBox.Text, 2) < ".5" Then txtBox = Null If Len(txtBox.Text) 4 Then txtBox = Null End Sub 'Here's where it fails. Sub SetLabel() 'This returns the TextBox number CtlNum = Mid(txtBox.Name, 8, Len(txtBox.Name)) laBl = "Label" & 3 MsgBox UserForm.Name.laBl.Caption End Sub All help will be appreciated. Thank you. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
On Sun, 20 Jul 2008 16:54:07 +0100, "Peter T" <peter_t@discussions
wrote: With a little more Google searching I've found how to access the label. The routine I'm using creates a UserForm dynamically, and places controls based on worksheet cell information. The UserForm name changes if it detects a similarly named UserForm in the Forms folder. I've got all that working well. Now, all I need is the method to access the userform from the class. Your routine "SetLabel" doesn't make any sense, what do you want it to do. Regards, Peter T "Stephen Newman" wrote in message .. . I am using a class I found here that works very well for my needs. Now I would like to reference and change the caption of a label of the same name (number) as the text box. The Class: Public WithEvents txtBox As MSForms.TextBox, CtlNum As String Public laBl As String Private Sub Class_Terminate() Set txtBox = Nothing End Sub Private Sub txtBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 46, 48 To 57 If Right(txtBox, 2) = ".5" Then KeyAscii = 0 If KeyAscii = 46 Then SendKeys ("5") ''' These are all number. No Problem Case Else ''' Some other kind of character. Beep and cancel it. Beep KeyAscii = 0 End Select SetLabel End Sub Private Sub txtBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 8 Then txtBox.Value = "" End Sub Private Sub txtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Len(txtBox.Text) = 3 And Right(txtBox.Text, 2) < ".5" Then txtBox = Null If Len(txtBox.Text) 4 Then txtBox = Null End Sub 'Here's where it fails. Sub SetLabel() 'This returns the TextBox number CtlNum = Mid(txtBox.Name, 8, Len(txtBox.Name)) 'Currently, Me is invalid. I need the name of the active UserForm MsgBox Me.Controls("Label" & CtlNum).Object.Caption End Sub All help will be appreciated. Thank you. I can write what I need into the routine later. Right now all I need to be able to do is access the control from the class. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
I have even less idea of what you are doing now than I had before. Anyway
just this bit Now, all I need is the method to access the userform from the class. Assuming you mean you want to reference the userform that contains your the textbox which is as referenced by Public WithEvents txtBox, try txtBox.Parent Regards, Peter T "Rumplestiltskin" wrote in message ... On Sun, 20 Jul 2008 16:54:07 +0100, "Peter T" <peter_t@discussions wrote: With a little more Google searching I've found how to access the label. The routine I'm using creates a UserForm dynamically, and places controls based on worksheet cell information. The UserForm name changes if it detects a similarly named UserForm in the Forms folder. I've got all that working well. Now, all I need is the method to access the userform from the class. Your routine "SetLabel" doesn't make any sense, what do you want it to do. Regards, Peter T "Stephen Newman" wrote in message .. . I am using a class I found here that works very well for my needs. Now I would like to reference and change the caption of a label of the same name (number) as the text box. The Class: Public WithEvents txtBox As MSForms.TextBox, CtlNum As String Public laBl As String Private Sub Class_Terminate() Set txtBox = Nothing End Sub Private Sub txtBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Select Case KeyAscii Case 46, 48 To 57 If Right(txtBox, 2) = ".5" Then KeyAscii = 0 If KeyAscii = 46 Then SendKeys ("5") ''' These are all number. No Problem Case Else ''' Some other kind of character. Beep and cancel it. Beep KeyAscii = 0 End Select SetLabel End Sub Private Sub txtBox_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 8 Then txtBox.Value = "" End Sub Private Sub txtBox_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If Len(txtBox.Text) = 3 And Right(txtBox.Text, 2) < ".5" Then txtBox = Null If Len(txtBox.Text) 4 Then txtBox = Null End Sub 'Here's where it fails. Sub SetLabel() 'This returns the TextBox number CtlNum = Mid(txtBox.Name, 8, Len(txtBox.Name)) 'Currently, Me is invalid. I need the name of the active UserForm MsgBox Me.Controls("Label" & CtlNum).Object.Caption End Sub All help will be appreciated. Thank you. I can write what I need into the routine later. Right now all I need to be able to do is access the control from the class. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
On Sun, 20 Jul 2008 17:28:33 +0100, "Peter T" <peter_t@discussions
wrote: I have even less idea of what you are doing now than I had before. Anyway just this bit Now, all I need is the method to access the userform from the class. Assuming you mean you want to reference the userform that contains your the textbox which is as referenced by Public WithEvents txtBox, try txtBox.Parent Regards, Peter T Thank for the input, but that didn't work. What I require is a method to reference the currently active UserForm. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
"Rumplestiltskin" wrote in message
... On Sun, 20 Jul 2008 17:28:33 +0100, "Peter T" <peter_t@discussions wrote: I have even less idea of what you are doing now than I had before. Anyway just this bit Now, all I need is the method to access the userform from the class. Assuming you mean you want to reference the userform that contains your the textbox which is as referenced by Public WithEvents txtBox, try txtBox.Parent Regards, Peter T Thank for the input, but that didn't work. What I require is a method to reference the currently active UserForm. Your routine SetLabel is called by the keypress event of a textbox on a form. Surely the form containing the textbox is the "currently active UserForm". That being the case txtBox.Parent will reference the form. If that's not the case you really need to explain what you are doing otherwise to assist is just a guessing game. Regards, Peter T |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
"Peter T" <peter_t@discussions wrote in message Your routine SetLabel is called by the keypress event of a textbox on a form. Surely the form containing the textbox is the "currently active UserForm". That being the case txtBox.Parent will reference the form. .....unless the textbox is "in" a frame or multipage in which case you'd use txtBox.Parent.Parent or if on a Multipage then you'd use txtBox.Parent.Parent.Parent Regards, Peter T |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reference Label from TextBox
On Sun, 20 Jul 2008 18:15:38 +0100, "Peter T" <peter_t@discussions
wrote: Yes, it works now. I'd left out the textbox number when I tried. Thanks very much for your help. "Peter T" <peter_t@discussions wrote in message Your routine SetLabel is called by the keypress event of a textbox on a form. Surely the form containing the textbox is the "currently active UserForm". That being the case txtBox.Parent will reference the form. ....unless the textbox is "in" a frame or multipage in which case you'd use txtBox.Parent.Parent or if on a Multipage then you'd use txtBox.Parent.Parent.Parent Regards, Peter T |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Floating textbox/label | Excel Programming | |||
Use a formula to populate a label from a textbox | Excel Discussion (Misc queries) | |||
Textbox and label formulas-continue | Excel Discussion (Misc queries) | |||
Centralizing Vertically of Label and TextBox | Excel Programming | |||
textbox result to label | Excel Programming |