Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Floating textbox/label Jock Excel Programming 6 March 10th 10 11:19 AM
Use a formula to populate a label from a textbox damorrison Excel Discussion (Misc queries) 5 September 4th 06 01:30 PM
Textbox and label formulas-continue damorrison Excel Discussion (Misc queries) 3 March 12th 06 06:32 PM
Centralizing Vertically of Label and TextBox zhj23 Excel Programming 0 March 2nd 06 03:28 PM
textbox result to label paradise Excel Programming 2 November 15th 03 01:10 PM


All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"