ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   check control names (https://www.excelbanter.com/excel-programming/397450-check-control-names.html)

stewart

check control names
 
I would like to be able to run a code that will check to see if a
control has a particular name and then tell me which one has that
name. I thought the code below would work but it does not do the
trick.

Private Sub btnSubmit_Click()

Dim C As Control
For Each C In Me.Controls
If C.Name = "txtnum1" Then
MsgBox C.Name
End If
Next C


End Sub

Additionally is there a way to use a wild card. For example show me
all textboxes that start with txtNum (txtNum1, txtNum2, etc)


Dave Peterson

check control names
 
It worked ok for me.

Maybe you need:

if lcase(c.name) = "txtnum1" then



stewart wrote:

I would like to be able to run a code that will check to see if a
control has a particular name and then tell me which one has that
name. I thought the code below would work but it does not do the
trick.

Private Sub btnSubmit_Click()

Dim C As Control
For Each C In Me.Controls
If C.Name = "txtnum1" Then
MsgBox C.Name
End If
Next C

End Sub

Additionally is there a way to use a wild card. For example show me
all textboxes that start with txtNum (txtNum1, txtNum2, etc)


--

Dave Peterson

stewart

check control names
 
On Sep 13, 8:55 pm, Dave Peterson wrote:
It worked ok for me.

Maybe you need:

if lcase(c.name) = "txtnum1" then



stewart wrote:

I would like to be able to run a code that will check to see if a
control has a particular name and then tell me which one has that
name. I thought the code below would work but it does not do the
trick.


Private Sub btnSubmit_Click()


Dim C As Control
For Each C In Me.Controls
If C.Name = "txtnum1" Then
MsgBox C.Name
End If
Next C


End Sub


Additionally is there a way to use a wild card. For example show me
all textboxes that start with txtNum (txtNum1, txtNum2, etc)


--

Dave Peterson


that did the trick...now is there a way to change that so i can search
for a wildcard. i want to find all textboxes that begin with txtNum


Dave Peterson

check control names
 
One way is to just look at the leftmost 6 chars:

if left(lcase(c.name),6) = "txtnum" then



stewart wrote:

On Sep 13, 8:55 pm, Dave Peterson wrote:
It worked ok for me.

Maybe you need:

if lcase(c.name) = "txtnum1" then



stewart wrote:

I would like to be able to run a code that will check to see if a
control has a particular name and then tell me which one has that
name. I thought the code below would work but it does not do the
trick.


Private Sub btnSubmit_Click()


Dim C As Control
For Each C In Me.Controls
If C.Name = "txtnum1" Then
MsgBox C.Name
End If
Next C


End Sub


Additionally is there a way to use a wild card. For example show me
all textboxes that start with txtNum (txtNum1, txtNum2, etc)


--

Dave Peterson


that did the trick...now is there a way to change that so i can search
for a wildcard. i want to find all textboxes that begin with txtNum


--

Dave Peterson

stewart

check control names
 
On Sep 13, 9:38 pm, Dave Peterson wrote:
One way is to just look at the leftmost 6 chars:

if left(lcase(c.name),6) = "txtnum" then



stewart wrote:

On Sep 13, 8:55 pm, Dave Peterson wrote:
It worked ok for me.


Maybe you need:


if lcase(c.name) = "txtnum1" then


stewart wrote:


I would like to be able to run a code that will check to see if a
control has a particular name and then tell me which one has that
name. I thought the code below would work but it does not do the
trick.


Private Sub btnSubmit_Click()


Dim C As Control
For Each C In Me.Controls
If C.Name = "txtnum1" Then
MsgBox C.Name
End If
Next C


End Sub


Additionally is there a way to use a wild card. For example show me
all textboxes that start with txtNum (txtNum1, txtNum2, etc)


--


Dave Peterson


that did the trick...now is there a way to change that so i can search
for a wildcard. i want to find all textboxes that begin with txtNum


--

Dave Peterson


thank you



All times are GMT +1. The time now is 11:49 AM.

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