Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Changing CheckBox Control Names | Excel Programming | |||
Using form control names in SQL | Excel Discussion (Misc queries) | |||
Control Deletion of Range Names | Excel Programming | |||
Variable Control Names | Excel Programming | |||
Form control names | Excel Programming |