ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Validation subroutine for textboxes (https://www.excelbanter.com/excel-programming/406789-validation-subroutine-textboxes.html)

chemicals

Validation subroutine for textboxes
 
I hav a Userform with 24 textboxes on it. I would like to call a generic
validation routine on each change event. My problem is how do I generically
reference the control's value in the Change event routine ?

Here's what I am trying to do:

Private Sub txtOverallForward_Change()
CheckRange (Me.txtOverallForward.Value)
End Sub

but is there a way to do something like:
Private Sub txtOverallForward_Change()
CheckRange (Me.ActiveControl.Value) <-------
End Sub



Dave Peterson

Validation subroutine for textboxes
 
Pass the textbox itself.

Private Sub txtOverallForward_Change()
CheckRange Me.txtOverallForward
End Sub

Sub CheckRange(TBox as msforms.textbox)
msgbox TBox.value
end sub



chemicals wrote:

I hav a Userform with 24 textboxes on it. I would like to call a generic
validation routine on each change event. My problem is how do I generically
reference the control's value in the Change event routine ?

Here's what I am trying to do:

Private Sub txtOverallForward_Change()
CheckRange (Me.txtOverallForward.Value)
End Sub

but is there a way to do something like:
Private Sub txtOverallForward_Change()
CheckRange (Me.ActiveControl.Value) <-------
End Sub


--

Dave Peterson

Rick Rothstein \(MVP - VB\)[_1360_]

Validation subroutine for textboxes
 
Or, since the OP appears to be calling the subroutine from within event
procedures for the actual controls themselves, don't pass any argument and
use the ActiveControl object to reference the control...

Private Sub txtOverallForward_Change()
CheckRange
End Sub

Sub CheckRange()
MsgBox ActiveControl.Value
End Sub

Rick


"Dave Peterson" wrote in message
...
Pass the textbox itself.

Private Sub txtOverallForward_Change()
CheckRange Me.txtOverallForward
End Sub

Sub CheckRange(TBox as msforms.textbox)
msgbox TBox.value
end sub



chemicals wrote:

I hav a Userform with 24 textboxes on it. I would like to call a generic
validation routine on each change event. My problem is how do I
generically
reference the control's value in the Change event routine ?

Here's what I am trying to do:

Private Sub txtOverallForward_Change()
CheckRange (Me.txtOverallForward.Value)
End Sub

but is there a way to do something like:
Private Sub txtOverallForward_Change()
CheckRange (Me.ActiveControl.Value) <-------
End Sub


--

Dave Peterson



chemicals

Validation subroutine for textboxes
 
THANKS RICK. That's what I wanted as I am lazy and didn't want to have to
type the textbox name in for every validation call....!



"Rick Rothstein (MVP - VB)" wrote:

Or, since the OP appears to be calling the subroutine from within event
procedures for the actual controls themselves, don't pass any argument and
use the ActiveControl object to reference the control...

Private Sub txtOverallForward_Change()
CheckRange
End Sub

Sub CheckRange()
MsgBox ActiveControl.Value
End Sub

Rick


"Dave Peterson" wrote in message
...
Pass the textbox itself.

Private Sub txtOverallForward_Change()
CheckRange Me.txtOverallForward
End Sub

Sub CheckRange(TBox as msforms.textbox)
msgbox TBox.value
end sub



chemicals wrote:

I hav a Userform with 24 textboxes on it. I would like to call a generic
validation routine on each change event. My problem is how do I
generically
reference the control's value in the Change event routine ?

Here's what I am trying to do:

Private Sub txtOverallForward_Change()
CheckRange (Me.txtOverallForward.Value)
End Sub

but is there a way to do something like:
Private Sub txtOverallForward_Change()
CheckRange (Me.ActiveControl.Value) <-------
End Sub


--

Dave Peterson




chemicals

Validation subroutine for textboxes
 
My bad!
ActiveControl.Value returns the value of the page in the Multipage (i.e.
0,1,2,3,4)

I have 5 multipage tabs each containing 24 textboxes so I needed to
reference the "active" textbox this way.....

ActiveControl.SelectedItem.ActiveControl.Value


"Rick Rothstein (MVP - VB)" wrote:

Or, since the OP appears to be calling the subroutine from within event
procedures for the actual controls themselves, don't pass any argument and
use the ActiveControl object to reference the control...

Private Sub txtOverallForward_Change()
CheckRange
End Sub

Sub CheckRange()
MsgBox ActiveControl.Value
End Sub

Rick


"Dave Peterson" wrote in message
...
Pass the textbox itself.

Private Sub txtOverallForward_Change()
CheckRange Me.txtOverallForward
End Sub

Sub CheckRange(TBox as msforms.textbox)
msgbox TBox.value
end sub



chemicals wrote:

I hav a Userform with 24 textboxes on it. I would like to call a generic
validation routine on each change event. My problem is how do I
generically
reference the control's value in the Change event routine ?

Here's what I am trying to do:

Private Sub txtOverallForward_Change()
CheckRange (Me.txtOverallForward.Value)
End Sub

but is there a way to do something like:
Private Sub txtOverallForward_Change()
CheckRange (Me.ActiveControl.Value) <-------
End Sub


--

Dave Peterson





All times are GMT +1. The time now is 10:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com