Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Control Names

Hi
I have a form for weekly input of data with lots of controls ending in the 3
letter day (ie Mon Tue etc), can I pass those 3 letters to a sub and then
concatenate them to the rest of the control name so I don't have to have a
sub for each day?

TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default Control Names

I THINK I understand what you are looking for.
Here's an example of a command button called 'cmdMON'.

The code behind the command button would be...
'/============================================/
Private Sub cmdMon_Click()
'passing a part of the command button's name
' to another subroutine that will show that
' name in a messagebox
Call TestName1(Right(Me.cmdMon.Name, 3))

'passing a part of the command button's name
' to another subroutine that will use the
' name to call a concatenated subroutine
Call TestName2(Right(Me.cmdMon.Name, 3))
End Sub
'/============================================/

In a REGULAR CODE Module....
'/============================================/
Public Sub TestName1(strName As String)
'This macro can be in the form or a regular code module
MsgBox strName
End Sub
'/============================================/
Public Sub TestName2(strName As String)
'concatenates 2 strings to run a macro
'this macro MUST be in a REGULAR CODE MODULE
' otherwise the 'Run' method will fail
Application.Run "Test" & strName
End Sub
'/============================================/
Public Sub TestMon()
'called from the concatenations in Sub TestName2
'this macro MUST be in a REGULAR CODE MODULE because
' TestName2 is in a regular code module
'It does NOT have to be in the same module
MsgBox "This is a test of running a macro " & _
"from concatenated strings."
End Sub
'/============================================/

HTH,
--
Gary Brown

If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.


"Graham Y" wrote:

Hi
I have a form for weekly input of data with lots of controls ending in the 3
letter day (ie Mon Tue etc), can I pass those 3 letters to a sub and then
concatenate them to the rest of the control name so I don't have to have a
sub for each day?

TIA

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Control Names

Gary Thanks, not quite what I was after, re-reading my post it was a little
brief

What I wanted to do was validation, I have three controls, a combobo & two
textboxes, I either want all empty (cmb.listitem= -1) or all with something in
(cmb.listitem -1) if this is not the case I want to make the background
colour pink. But rather than writing the same code 7 times for each week day
I wanted one sub that I could send "Sat" to that would work on cmbSat,
txtSSat & txtESat

So I want to be able say something like cmb & "Sat" & .Backcolor = RGB(r,g,b)

Thanks


"Gary L Brown" wrote:

I THINK I understand what you are looking for.
Here's an example of a command button called 'cmdMON'.

The code behind the command button would be...
'/============================================/
Private Sub cmdMon_Click()
'passing a part of the command button's name
' to another subroutine that will show that
' name in a messagebox
Call TestName1(Right(Me.cmdMon.Name, 3))

'passing a part of the command button's name
' to another subroutine that will use the
' name to call a concatenated subroutine
Call TestName2(Right(Me.cmdMon.Name, 3))
End Sub
'/============================================/

In a REGULAR CODE Module....
'/============================================/
Public Sub TestName1(strName As String)
'This macro can be in the form or a regular code module
MsgBox strName
End Sub
'/============================================/
Public Sub TestName2(strName As String)
'concatenates 2 strings to run a macro
'this macro MUST be in a REGULAR CODE MODULE
' otherwise the 'Run' method will fail
Application.Run "Test" & strName
End Sub
'/============================================/
Public Sub TestMon()
'called from the concatenations in Sub TestName2
'this macro MUST be in a REGULAR CODE MODULE because
' TestName2 is in a regular code module
'It does NOT have to be in the same module
MsgBox "This is a test of running a macro " & _
"from concatenated strings."
End Sub
'/============================================/

HTH,
--
Gary Brown

If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.


"Graham Y" wrote:

Hi
I have a form for weekly input of data with lots of controls ending in the 3
letter day (ie Mon Tue etc), can I pass those 3 letters to a sub and then
concatenate them to the rest of the control name so I don't have to have a
sub for each day?

TIA

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
Changing CheckBox Control Names grime[_7_] Excel Programming 4 October 27th 05 01:30 PM
Using form control names in SQL AaronC Excel Discussion (Misc queries) 0 July 14th 05 05:13 PM
Control Deletion of Range Names Alex Hatzisavas[_5_] Excel Programming 0 September 22nd 04 08:55 PM
Variable Control Names Garry Jones Excel Programming 4 October 3rd 03 10:45 PM
Form control names Howard Kaikow Excel Programming 6 July 26th 03 08:24 PM


All times are GMT +1. The time now is 06:02 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"