View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default 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.