Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Passing a control to a Sub


Hi,

I've got a form with some labels on it. On the click event of one of the
labels, I'd like to pass the label to another sub in the code for that form.
It seems to pass the caption for the label.

I tried, within the click event, to assign the label (me.label1) to a
variable that I declared as a label. This also failed.

Is there a way to make this work?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Passing a control to a Sub


a = me.label1 'will pas the text for the label
set a = me.label1 'will pass the label object

"Art" wrote:

Hi,

I've got a form with some labels on it. On the click event of one of the
labels, I'd like to pass the label to another sub in the code for that form.
It seems to pass the caption for the label.

I tried, within the click event, to assign the label (me.label1) to a
variable that I declared as a label. This also failed.

Is there a way to make this work?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Passing a control to a Sub

There are two different labels that you can use in excel. One is the one from
the Forms toolbar and the other is the activex control that you use in userforms
(and on the control toolbox toolbar).

You have to make sure that you use the right one in the called procedu

Option Explicit
Private Sub CommandButton1_Click()
Call SubRoutineNameHere(Me.Label1)
End Sub
Sub SubRoutineNameHere(myLabel As msforms.Label)
MsgBox myLabel.Caption
End Sub




Art wrote:

Hi,

I've got a form with some labels on it. On the click event of one of the
labels, I'd like to pass the label to another sub in the code for that form.
It seems to pass the caption for the label.

I tried, within the click event, to assign the label (me.label1) to a
variable that I declared as a label. This also failed.

Is there a way to make this work?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Passing a control to a Sub

Joel,

I appreciate your response, but that didn't seem to work for me. The
suggestion by Dave, next response, did the trick. It may be that you had
already assumed that I was doing what Dave suggested.



"Joel" wrote:

a = me.label1 'will pas the text for the label
set a = me.label1 'will pass the label object

"Art" wrote:

Hi,

I've got a form with some labels on it. On the click event of one of the
labels, I'd like to pass the label to another sub in the code for that form.
It seems to pass the caption for the label.

I tried, within the click event, to assign the label (me.label1) to a
variable that I declared as a label. This also failed.

Is there a way to make this work?


  #5   Report Post  
Posted to microsoft.public.excel.programming
Art Art is offline
external usenet poster
 
Posts: 587
Default Passing a control to a Sub

Dave,

Thanks, that did it! I didn't realize that there was a different type that
I needed to use. Thanks very much.



"Dave Peterson" wrote:

There are two different labels that you can use in excel. One is the one from
the Forms toolbar and the other is the activex control that you use in userforms
(and on the control toolbox toolbar).

You have to make sure that you use the right one in the called procedu

Option Explicit
Private Sub CommandButton1_Click()
Call SubRoutineNameHere(Me.Label1)
End Sub
Sub SubRoutineNameHere(myLabel As msforms.Label)
MsgBox myLabel.Caption
End Sub




Art wrote:

Hi,

I've got a form with some labels on it. On the click event of one of the
labels, I'd like to pass the label to another sub in the code for that form.
It seems to pass the caption for the label.

I tried, within the click event, to assign the label (me.label1) to a
variable that I declared as a label. This also failed.

Is there a way to make this work?


--

Dave Peterson

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
Passing a Control as an Argument Goofy Excel Programming 14 November 1st 06 11:38 AM
Passing a Forms Control to Function Pflugs Excel Programming 5 August 24th 06 10:34 PM
passing range from RefEdit control Greg Excel Programming 1 April 25th 06 04:51 AM
Passing Control when workbooks have the same name shawb[_3_] Excel Programming 5 September 28th 05 01:59 PM
Passing the Name of a Control Between Macros Sandy Excel Programming 2 May 4th 05 03:02 PM


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