473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to Capture the Name of the Current Control

Hi,
I'm trying to capture the name of the current control (which is a text
box) in the validating procedure as well as the text in the control,
which I intend to pass to another subroutine for coding efficiency.
I've tried two different options, neither works:

Private Sub thisTB_Validating....
Dim strTest as String = Me.Text
Dim strName as String = Me.Name
' this yields values for the form, not the control

'also tried
Dim strTest as String = ActiveControl.Text
Dim strName as String = ActiveControl.Name
' this fails as it yields values for the control that the user clicks
to, not the one being validated.

I'm guessing that this is pretty simple. Can anyone help?

Thanks,
Randy

May 10 '07 #1
4 5097
Can anybody help me with this?

May 10 '07 #2
On May 10, 3:49 pm, Randy <spam.eastl...@gmail.comwrote:
Can anybody help me with this?
Cast the sender into a textbox - then it will expose the textbox's
properties and methods.

i.e.

Private Sub TextBoxes_Validating(ByVal sender As System.Object,
ByVal e As System.ComponentModel.CancelEventArgs) Handles
TextBox2.Validating, TextBox1.Validating
MessageBox.Show(DirectCast(sender, TextBox).Name)
End Sub

Thanks,

Seth Rowe

May 10 '07 #3
That works. Thanks a lot.

Randy

May 11 '07 #4

"Randy" <sp***********@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
Hi,
I'm trying to capture the name of the current control (which is a text
box) in the validating procedure as well as the text in the control,
which I intend to pass to another subroutine for coding efficiency.
I've tried two different options, neither works:

Private Sub thisTB_Validating....
Dim strTest as String = Me.Text
Dim strName as String = Me.Name
' this yields values for the form, not the control

'also tried
Dim strTest as String = ActiveControl.Text
Dim strName as String = ActiveControl.Name
' this fails as it yields values for the control that the user clicks
to, not the one being validated.

I'm guessing that this is pretty simple. Can anyone help?

Thanks,
Randy
+++++++++
(assuming you have "sender as Object" as an Arg) :
dim tb as TextBox = CType(sender, TextBox)
Dim strNameOfTextBox as String = tb.Name
....
May 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ron Vecchi | last post by:
I need to allow my control when it is visible to capture the mouse and not let any other control react to mouse events until control is hidden. Similar to ContextMenu Any Suggestions --...
0
by: Jon Paal | last post by:
To produce 1 dynamic chart, I add a control to my aspx page positioned in a placeholder. I need to have more than one chart and need to capture the chart control output so it can be complemented...
0
by: Jim McGivney | last post by:
IN VWD, on an aspx page I have a DetailsView control. I have placed an AccessDataSource (AccessDataSource3) in the EditItemTemplate for the Row called "Sex". I want to programatically change the...
3
by: clintonG | last post by:
// The ServerVariables collection can help me build this: http://xp1/METRO2/HomePage.aspx // URL & QueryString generated by the 2.0 Login control click event. // What I need to capture is...
2
by: RLN | last post by:
I have this error message format I use for my error handling in all modules, both in vba code inside of a form and vba code that is outside of forms: MsgBox Err.Number & "-" & Err.Description,...
0
by: davidr | last post by:
Hi, I been stuck on this for a week or more. So please help! I have a menu were a user can click a button and a user control is loaded into the page. A problem occurs when trying to load a...
3
by: MLH | last post by:
Looking to use something to determine name of control with focus in A97 app. Is there something like Screen.currentcontrol.Name?
13
by: =?Utf-8?B?RG9uYWxkIEZpc2hlcg==?= | last post by:
Hello. I'm trying to capture a controls value: a dropdown box with two selections (either "Red" or "Blue") keeps returning the value "Red" even if "Blue" is selected?
4
beacon
by: beacon | last post by:
Hi everybody, I have a form (frmDeficiency) with a tab control (called deficiencyTabControl) that has 8 tabs. The first tab is for general information, but the 2nd through the 8th tabs have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.