ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Scrutinizing Controls on Form for Certain Value (https://www.excelbanter.com/excel-programming/335264-scrutinizing-controls-form-certain-value.html)

scantor145[_15_]

Scrutinizing Controls on Form for Certain Value
 

Excel 2003 w/Visual Basic 6.3

I have a form with several types of controls; labels, command buttons
check boxes and text boxes.

The text boxes take user input in the form of numbers.
All text boxes have names of the form "txtNAME".

e.g. txtBUN, txtTRIG, txtAST, etc.

The user might then assign a number to certain text boxes.

e.g. txtBUN = 7, txtTRIG = 15 , txtAST = 21, etc.

What I would like to do is query the form to check if any of thes
numbers match a value that is derived previously, then procee
accordingly.

What I have below DOES NOT work and I can't figure out a way around it
I think it has to do with TextBox.Value which I'm not sure is viable.
Any suggestions?


Code
-------------------
Dim TextBox As Control

For Each TextBox In frmReagInv.Controls
If Left(TextBox.Name, 3) = "txt" Then
If TextBox.Value = Z Then
ChemName(K) = Mid(TextBox.Name, 4)
End If
End If
Next TextBo
-------------------

--
scantor14
-----------------------------------------------------------------------
scantor145's Profile: http://www.excelforum.com/member.php...fo&userid=1476
View this thread: http://www.excelforum.com/showthread.php?threadid=38935


Bob Phillips[_7_]

Scrutinizing Controls on Form for Certain Value
 
Dim ctl As Control

For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Then
If ctl.Value = Z Then
ChemName(K) = Mid(ctl.Name, 4)
End If
End If
Next ctl


--
HTH

Bob Phillips

"scantor145" wrote
in message ...

Excel 2003 w/Visual Basic 6.3

I have a form with several types of controls; labels, command buttons,
check boxes and text boxes.

The text boxes take user input in the form of numbers.
All text boxes have names of the form "txtNAME".

e.g. txtBUN, txtTRIG, txtAST, etc.

The user might then assign a number to certain text boxes.

e.g. txtBUN = 7, txtTRIG = 15 , txtAST = 21, etc.

What I would like to do is query the form to check if any of these
numbers match a value that is derived previously, then proceed
accordingly.

What I have below DOES NOT work and I can't figure out a way around it.
I think it has to do with TextBox.Value which I'm not sure is viable.
Any suggestions?


Code:
--------------------
Dim TextBox As Control

For Each TextBox In frmReagInv.Controls
If Left(TextBox.Name, 3) = "txt" Then
If TextBox.Value = Z Then
ChemName(K) = Mid(TextBox.Name, 4)
End If
End If
Next TextBox
--------------------


--
scantor145
------------------------------------------------------------------------
scantor145's Profile:

http://www.excelforum.com/member.php...o&userid=14766
View this thread: http://www.excelforum.com/showthread...hreadid=389356




scantor145[_16_]

Scrutinizing Controls on Form for Certain Value
 

I tried your suggestion as well as the following:


Code
-------------------
Dim ctl As Control

For Each ctl In frmReagInv.Controls
If TypeOf ctl Is TextBox Then
If Left(ctl.Name, 3) = "txt" Then
If ctl.Text = "Z" Then
ChemName(K) = Mid$(ctl.Name, 4)
End If
End If
End If
Next ct
-------------------


For some reason, which is bothering the hell out of me, the control
aren't recognized as TextBoxes. That is, when the program encounter
the line


Code
-------------------
If TypeOf ctl Is TextBox The
-------------------


it then precedes to jump to the last End If statement, although i
encounters a control, a textbox with a name such as "txtAmyl"
Any clues

--
scantor14
-----------------------------------------------------------------------
scantor145's Profile: http://www.excelforum.com/member.php...fo&userid=1476
View this thread: http://www.excelforum.com/showthread.php?threadid=38935


Bob Phillips[_7_]

Scrutinizing Controls on Form for Certain Value
 
Put a Debug.Print Typename(ctl), ctl.Name

in the code and see what it thinks it is

--
HTH

Bob Phillips

"scantor145" wrote
in message ...

I tried your suggestion as well as the following:


Code:
--------------------
Dim ctl As Control

For Each ctl In frmReagInv.Controls
If TypeOf ctl Is TextBox Then
If Left(ctl.Name, 3) = "txt" Then
If ctl.Text = "Z" Then
ChemName(K) = Mid$(ctl.Name, 4)
End If
End If
End If
Next ctl
--------------------


For some reason, which is bothering the hell out of me, the controls
aren't recognized as TextBoxes. That is, when the program encounters
the line


Code:
--------------------
If TypeOf ctl Is TextBox Then
--------------------


it then precedes to jump to the last End If statement, although it
encounters a control, a textbox with a name such as "txtAmyl"
Any clues?


--
scantor145
------------------------------------------------------------------------
scantor145's Profile:

http://www.excelforum.com/member.php...o&userid=14766
View this thread: http://www.excelforum.com/showthread...hreadid=389356





All times are GMT +1. The time now is 04:31 PM.

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