PC Review


Reply
Thread Tools Rate Thread

Code to Read Caption on Command Button

 
 
=?Utf-8?B?SkhL?=
Guest
Posts: n/a
 
      3rd Jun 2005
I'm trying to write code to create a Function that will, depending on the
Command Button pressed on a form, take the name label (caption) of the button
and assign the text to a string that I can then do something with.

I know how to do this on an individual button basis as a private sub, but I
have a need to do this with several buttons on a form and I don't want to
have to copy the code and edit it for each button.

Any assistance would be appreciated.
 
Reply With Quote
 
 
 
 
Steve Schapel
Guest
Posts: n/a
 
      4th Jun 2005
JHK,

I think you could use this in your function:
Screen.ActiveControl.Caption

--
Steve Schapel, Microsoft Access MVP


JHK wrote:
> I'm trying to write code to create a Function that will, depending on the
> Command Button pressed on a form, take the name label (caption) of the button
> and assign the text to a string that I can then do something with.
>
> I know how to do this on an individual button basis as a private sub, but I
> have a need to do this with several buttons on a form and I don't want to
> have to copy the code and edit it for each button.
>
> Any assistance would be appreciated.

 
Reply With Quote
 
=?Utf-8?B?SkhL?=
Guest
Posts: n/a
 
      4th Jun 2005
Screen.ActiveControl.Caption does appear to be valid. (I'm using 2002)

Any ideas?

"Steve Schapel" wrote:

> JHK,
>
> I think you could use this in your function:
> Screen.ActiveControl.Caption
>
> --
> Steve Schapel, Microsoft Access MVP
>
>
> JHK wrote:
> > I'm trying to write code to create a Function that will, depending on the
> > Command Button pressed on a form, take the name label (caption) of the button
> > and assign the text to a string that I can then do something with.
> >
> > I know how to do this on an individual button basis as a private sub, but I
> > have a need to do this with several buttons on a form and I don't want to
> > have to copy the code and edit it for each button.
> >
> > Any assistance would be appreciated.

>

 
Reply With Quote
 
=?Utf-8?B?SkhL?=
Guest
Posts: n/a
 
      4th Jun 2005
Disregard. Your suggestion works fine. Thanks very much.

"JHK" wrote:

> Screen.ActiveControl.Caption does appear to be valid. (I'm using 2002)
>
> Any ideas?
>
> "Steve Schapel" wrote:
>
> > JHK,
> >
> > I think you could use this in your function:
> > Screen.ActiveControl.Caption
> >
> > --
> > Steve Schapel, Microsoft Access MVP
> >
> >
> > JHK wrote:
> > > I'm trying to write code to create a Function that will, depending on the
> > > Command Button pressed on a form, take the name label (caption) of the button
> > > and assign the text to a string that I can then do something with.
> > >
> > > I know how to do this on an individual button basis as a private sub, but I
> > > have a need to do this with several buttons on a form and I don't want to
> > > have to copy the code and edit it for each button.
> > >
> > > Any assistance would be appreciated.

> >

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      4th Jun 2005
Its just like a control.... Me!cmdButtonName.Caption

or the full reference [Forms]![frmReservations]![cmdButtonName].caption

JHK wrote:
> Screen.ActiveControl.Caption does appear to be valid. (I'm using 2002)
>
> Any ideas?
>
> "Steve Schapel" wrote:
>
>
>>JHK,
>>
>>I think you could use this in your function:
>> Screen.ActiveControl.Caption
>>
>>--
>>Steve Schapel, Microsoft Access MVP
>>
>>
>>JHK wrote:
>>
>>>I'm trying to write code to create a Function that will, depending on the
>>>Command Button pressed on a form, take the name label (caption) of the button
>>>and assign the text to a string that I can then do something with.
>>>
>>>I know how to do this on an individual button basis as a private sub, but I
>>>have a need to do this with several buttons on a form and I don't want to
>>>have to copy the code and edit it for each button.
>>>
>>>Any assistance would be appreciated.

>>

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      4th Jun 2005
Sorry about that...if you want to reuse the code, write the sub and then
call the specific sub from the onClick event of each button. This is
the only way to have the same code execute for multiple buttons, but it
reduces the amount of code.

sub mySubWhatever
(code)
end sub

sub cmdPrint_onClick()
call mySubWhatever
end sub



JHK wrote:
> Screen.ActiveControl.Caption does appear to be valid. (I'm using 2002)
>
> Any ideas?
>
> "Steve Schapel" wrote:
>
>
>>JHK,
>>
>>I think you could use this in your function:
>> Screen.ActiveControl.Caption
>>
>>--
>>Steve Schapel, Microsoft Access MVP
>>
>>
>>JHK wrote:
>>
>>>I'm trying to write code to create a Function that will, depending on the
>>>Command Button pressed on a form, take the name label (caption) of the button
>>>and assign the text to a string that I can then do something with.
>>>
>>>I know how to do this on an individual button basis as a private sub, but I
>>>have a need to do this with several buttons on a form and I don't want to
>>>have to copy the code and edit it for each button.
>>>
>>>Any assistance would be appreciated.

>>

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      4th Jun 2005
I'm just not quite with it, make is a function and pass the value of the
button to it

function myFunction(strCaption as String)
end function

sub cmdPrint_onClick()
t=myFunction(Me!cmdPrint.caption)
end sub

JHK wrote:
> Disregard. Your suggestion works fine. Thanks very much.
>
> "JHK" wrote:
>
>
>>Screen.ActiveControl.Caption does appear to be valid. (I'm using 2002)
>>
>>Any ideas?
>>
>>"Steve Schapel" wrote:
>>
>>
>>>JHK,
>>>
>>>I think you could use this in your function:
>>> Screen.ActiveControl.Caption
>>>
>>>--
>>>Steve Schapel, Microsoft Access MVP
>>>
>>>
>>>JHK wrote:
>>>
>>>>I'm trying to write code to create a Function that will, depending on the
>>>>Command Button pressed on a form, take the name label (caption) of the button
>>>>and assign the text to a string that I can then do something with.
>>>>
>>>>I know how to do this on an individual button basis as a private sub, but I
>>>>have a need to do this with several buttons on a form and I don't want to
>>>>have to copy the code and edit it for each button.
>>>>
>>>>Any assistance would be appreciated.
>>>

 
Reply With Quote
 
=?Utf-8?B?SkhL?=
Guest
Posts: n/a
 
      5th Jun 2005
Got it. It works fine. Thanks.

"David C. Holley" wrote:

> Sorry about that...if you want to reuse the code, write the sub and then
> call the specific sub from the onClick event of each button. This is
> the only way to have the same code execute for multiple buttons, but it
> reduces the amount of code.
>
> sub mySubWhatever
> (code)
> end sub
>
> sub cmdPrint_onClick()
> call mySubWhatever
> end sub
>
>
>
> JHK wrote:
> > Screen.ActiveControl.Caption does appear to be valid. (I'm using 2002)
> >
> > Any ideas?
> >
> > "Steve Schapel" wrote:
> >
> >
> >>JHK,
> >>
> >>I think you could use this in your function:
> >> Screen.ActiveControl.Caption
> >>
> >>--
> >>Steve Schapel, Microsoft Access MVP
> >>
> >>
> >>JHK wrote:
> >>
> >>>I'm trying to write code to create a Function that will, depending on the
> >>>Command Button pressed on a form, take the name label (caption) of the button
> >>>and assign the text to a string that I can then do something with.
> >>>
> >>>I know how to do this on an individual button basis as a private sub, but I
> >>>have a need to do this with several buttons on a form and I don't want to
> >>>have to copy the code and edit it for each button.
> >>>
> >>>Any assistance would be appreciated.
> >>

>

 
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
COMMAND BUTTON CAPTION Chai Microsoft Access Form Coding 2 13th Apr 2010 04:33 PM
RE: Command Button Caption - VBA JLGWhiz Microsoft Excel Programming 0 31st Jul 2008 07:00 PM
command button caption =?Utf-8?B?TGVzSHVybGV5?= Microsoft Excel Programming 2 16th Nov 2007 11:14 PM
Re: Command Button Caption Dave Peterson Microsoft Excel Misc 0 7th Aug 2004 12:36 AM
Re: Command Button Caption Dave Peterson Microsoft Excel Misc 0 6th Aug 2004 08:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:19 AM.