PC Review


Reply
Thread Tools Rate Thread

Control Names

 
 
=?Utf-8?B?R3JhaGFtIFk=?=
Guest
Posts: n/a
 
      10th Oct 2006
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 With Quote
 
 
 
 
=?Utf-8?B?R2FyeSBMIEJyb3du?=
Guest
Posts: n/a
 
      10th Oct 2006
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
gary_brown@ge_NOSPAM.com
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 With Quote
 
=?Utf-8?B?R3JhaGFtIFk=?=
Guest
Posts: n/a
 
      10th Oct 2006
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
> gary_brown@ge_NOSPAM.com
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reserved Control Names Graham Microsoft ASP .NET 5 19th Jun 2006 09:26 PM
VB control names Nmidia Microsoft Access 6 20th Apr 2006 09:42 AM
Using control array run time with different control names AB Microsoft VB .NET 4 18th Jan 2006 02:22 PM
Using form control names in SQL AaronC Microsoft Excel Misc 0 14th Jul 2005 05:13 PM
Should Form Control names differ from Field names? Bam Bam Microsoft Access 6 22nd Sep 2004 08:08 AM


Features
 

Advertising
 

Newsgroups
 


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