Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Pass control to a function/subroutine

I want to popup a shortcut menu whenever a user right clicks in a textbox on
my userform. I initially tried to use:

ctrl = Screen.Activecontrol 'this is how I would do it in Access

but this did not work. Since I have several userforms, and I want this
subroutine to work for each of them, I tried declaring the control in the
subroutines declaration statement:

Public Sub EditMenuPopup(ctrl as Textbox)

Unfortunately, with this approach, I encountered two problems. When I called
the sub using:

Call EditMenuPopup(me.txt_SomeControl)

I got an error because it was trying to pass the value of the control, not
the actual control. When I tried:

Call EditMenuPopup(me.ActiveControl)

I got a type mismatch because it believes that the active control is a
multipage control, not the textbox that actually has the focus.

In some forms, the textbox might be on a multipage (tab) control, in others
it will just be on the main form, and this would probably work.

I thought about passing the userform and control names but don't know how to
refer to refer to the form with its name. In Access I would use:

Forms(strFormName)

Any ideas how to work approach this issue would be greatly appreciated

Dale

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Pass control to a function/subroutine

In the userform's code module, use the following event for your text box:

Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, _
ByVal X As Single, ByVal Y As Single)
If Button = xlSecondaryButton Then
TheProc CTL:=Me.TextBox1
End If
End Sub

Then, in regular code moudle, use

Sub TheProc(CTL As MSForms.Control)
If TypeOf CTL Is MSForms.TextBox Then
MsgBox "Control Is A Text Box: " & CTL.Name & vbCrLf & _
CTL.Text
Else
Debug.Print "NOT A TEXT BOX: " & CTL.Name
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



"Dale Fye" wrote in message
...
I want to popup a shortcut menu whenever a user right clicks in a textbox
on
my userform. I initially tried to use:

ctrl = Screen.Activecontrol 'this is how I would do it in Access

but this did not work. Since I have several userforms, and I want this
subroutine to work for each of them, I tried declaring the control in the
subroutines declaration statement:

Public Sub EditMenuPopup(ctrl as Textbox)

Unfortunately, with this approach, I encountered two problems. When I
called
the sub using:

Call EditMenuPopup(me.txt_SomeControl)

I got an error because it was trying to pass the value of the control, not
the actual control. When I tried:

Call EditMenuPopup(me.ActiveControl)

I got a type mismatch because it believes that the active control is a
multipage control, not the textbox that actually has the focus.

In some forms, the textbox might be on a multipage (tab) control, in
others
it will just be on the main form, and this would probably work.

I thought about passing the userform and control names but don't know how
to
refer to refer to the form with its name. In Access I would use:

Forms(strFormName)

Any ideas how to work approach this issue would be greatly appreciated

Dale

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Pass control to a function/subroutine

Presuming that you have created a commandbar, how about using the DblClick
event to pop it up.


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Dale Fye" wrote in message
...
I want to popup a shortcut menu whenever a user right clicks in a textbox
on
my userform. I initially tried to use:

ctrl = Screen.Activecontrol 'this is how I would do it in Access

but this did not work. Since I have several userforms, and I want this
subroutine to work for each of them, I tried declaring the control in the
subroutines declaration statement:

Public Sub EditMenuPopup(ctrl as Textbox)

Unfortunately, with this approach, I encountered two problems. When I
called
the sub using:

Call EditMenuPopup(me.txt_SomeControl)

I got an error because it was trying to pass the value of the control, not
the actual control. When I tried:

Call EditMenuPopup(me.ActiveControl)

I got a type mismatch because it believes that the active control is a
multipage control, not the textbox that actually has the focus.

In some forms, the textbox might be on a multipage (tab) control, in
others
it will just be on the main form, and this would probably work.

I thought about passing the userform and control names but don't know how
to
refer to refer to the form with its name. In Access I would use:

Forms(strFormName)

Any ideas how to work approach this issue would be greatly appreciated

Dale

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Pass control to a function/subroutine

The popup works fine (mousedown, check for right button). The problem is
that before I popup it up, I want to enable/disable several of the controls
based on information in the textbox.

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



"Bob Phillips" wrote:

Presuming that you have created a commandbar, how about using the DblClick
event to pop it up.


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Dale Fye" wrote in message
...
I want to popup a shortcut menu whenever a user right clicks in a textbox
on
my userform. I initially tried to use:

ctrl = Screen.Activecontrol 'this is how I would do it in Access

but this did not work. Since I have several userforms, and I want this
subroutine to work for each of them, I tried declaring the control in the
subroutines declaration statement:

Public Sub EditMenuPopup(ctrl as Textbox)

Unfortunately, with this approach, I encountered two problems. When I
called
the sub using:

Call EditMenuPopup(me.txt_SomeControl)

I got an error because it was trying to pass the value of the control, not
the actual control. When I tried:

Call EditMenuPopup(me.ActiveControl)

I got a type mismatch because it believes that the active control is a
multipage control, not the textbox that actually has the focus.

In some forms, the textbox might be on a multipage (tab) control, in
others
it will just be on the main form, and this would probably work.

I thought about passing the userform and control names but don't know how
to
refer to refer to the form with its name. In Access I would use:

Forms(strFormName)

Any ideas how to work approach this issue would be greatly appreciated

Dale

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Pass control to a function/subroutine

Chip,

Thanks, that resolved the first issue.

Now that I am able to enable/disable some of the commandbar items based on
the value in the textbox, how do I pass the control to the function that is
run in the OnAction event of the commandbar?

Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



"Chip Pearson" wrote:

In the userform's code module, use the following event for your text box:

Private Sub TextBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, _
ByVal X As Single, ByVal Y As Single)
If Button = xlSecondaryButton Then
TheProc CTL:=Me.TextBox1
End If
End Sub

Then, in regular code moudle, use

Sub TheProc(CTL As MSForms.Control)
If TypeOf CTL Is MSForms.TextBox Then
MsgBox "Control Is A Text Box: " & CTL.Name & vbCrLf & _
CTL.Text
Else
Debug.Print "NOT A TEXT BOX: " & CTL.Name
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)



"Dale Fye" wrote in message
...
I want to popup a shortcut menu whenever a user right clicks in a textbox
on
my userform. I initially tried to use:

ctrl = Screen.Activecontrol 'this is how I would do it in Access

but this did not work. Since I have several userforms, and I want this
subroutine to work for each of them, I tried declaring the control in the
subroutines declaration statement:

Public Sub EditMenuPopup(ctrl as Textbox)

Unfortunately, with this approach, I encountered two problems. When I
called
the sub using:

Call EditMenuPopup(me.txt_SomeControl)

I got an error because it was trying to pass the value of the control, not
the actual control. When I tried:

Call EditMenuPopup(me.ActiveControl)

I got a type mismatch because it believes that the active control is a
multipage control, not the textbox that actually has the focus.

In some forms, the textbox might be on a multipage (tab) control, in
others
it will just be on the main form, and this would probably work.

I thought about passing the userform and control names but don't know how
to
refer to refer to the form with its name. In Access I would use:

Forms(strFormName)

Any ideas how to work approach this issue would be greatly appreciated

Dale

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.


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
Pass array of sheet names to subroutine HartJF Excel Programming 7 September 21st 07 10:48 PM
Control Click Subroutine (BHatMJ) BHatMJ Excel Programming 4 May 31st 07 07:46 PM
Function parameters: trying to pass a control Mole Hunter Excel Programming 8 May 7th 07 10:41 AM
Pass a Variable List Of Values To Subroutine or Function Dean Hinson[_3_] Excel Programming 2 January 28th 05 06:49 PM
How to pass a workshhet name as a parameter into a subroutine ? yigalb Excel Discussion (Misc queries) 4 January 9th 05 10:28 AM


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