Anyone have some code that actually works to give a right click context menu on a textbox. I just want to be able to paste to the box with the mouse.
I have tried some code from this site but without success.
Printable View
Anyone have some code that actually works to give a right click context menu on a textbox. I just want to be able to paste to the box with the mouse.
I have tried some code from this site but without success.
I tried this one and it threw up an error.
Run-time error '13': Type mismatch
Debug took me to this statement
Code:' Set object reference to the textboxthat was clicked
Set oControl = oForm.ActiveControl
It notes on the page " It has been tested in Word 97 and Word 2000 under Windows 98 and 2000."
I am on Word 2010, so something needs to be fixed in that .bas file I guess.
It works in all Word versions to date - see attached
your example works correctly but not in my form
I just made my own test example on another form and it works fine.
So what could be wrong with the other one?
I found the difference.
My form has a Mulitpage element with the textbox on that.
Try your example with that setup, if you would please and see if you get the error.
UPDATE
I change the code in the mocPopupMenu
Dim oControl As MSForms.MultiPage
Now it is working.... EXCEPT paste... I just can't believe this.
Attachment 26159
here is the sample but with the box on a multipage.
If you are able to get it to paste with the menu it would be fantastic.
Change the content of procedure ShowPopup a littleApply the same patch in the EnableMenuItems procedure.Code:Public Sub ShowPopup(oForm As UserForm, strCaption As String, X As Single, Y As Single)
Dim oControl As MSForms.Control
Static click_flag As Long
' The following is required because the MouseDown event
' fires twice when right-clicked !!
click_flag = click_flag + 1
' Do nothing on first firing of MouseDown event
If (click_flag Mod 2 <> 0) Then Exit Sub
' Set object reference to the textboxthat was clicked
Set oControl = oForm.ActiveControl
If TypeName(oControl) = "MultiPage" Then
Set oControl = oControl.Pages(oControl.Value).ActiveControl
End If
' If click is outside the textbox, do nothing
If X > oControl.Width Or Y > oControl.Height Or X < 0 Or Y < 0 Then Exit Sub
(...)
Artik
I am not getting it to work on my form. Paste is greyed out. So could it be the code that is checking the clipboard is also wrong now.? Please if possible can you do the fix in the .docm example I uploaded and check it works, then upload the working .docm
I have gone in circles with this for too long. :banghead:
Thank you for your assistance.
Is there anything copied to the clipboard? You can't paste if the clipboard is empty.
yes there certainly is. I copy text from the document each time I try this.
I did apply it there also.
Shall I post the .bas file ?
Change both Dim statements for oControl to
See attachedCode:Dim oControl As Object
Thanks, I can see that works and so the only other difference is that I have a frame in the MultiPage and it is this that is now causing it not to work. When I move the textbox outside the frame it works. So is there a fix for that setup. Sorry for all this but but. There was no mention of limitations for this .bas file. It appeared generic.
Can you show your example after all the changes?
Artik
sure thanks for sticking with me.
A few words of explanation.
In the original code, the author assumed that TextBox will be in a container that is UserFormBut UserForm is not the only possible container. The UserForm container may also contain a MultiPage container and a Frame container. At your place, TextBox2 is directly in the UserForm container. In contrast, TextBox1 is strongly nested. It's in the Frame container, and this one is in the Multipage container that is in the UserForm container. To find out which control is active, you must go through all the containers.Code:Set oControl = oForm.ActiveControl
The corrected code, in addition to placing the nested control in Frame/MultiPage/UserForm, also provides for other nesting: MultiPage/Frame/UserForm. However, it does NOT provide e.g. Frame/Frame/UserForm etc.
In both procedures, improve on this passage:Code:Set oControl = oForm.ActiveControl
If TypeName(oControl) = "MultiPage" Then
Set oControl = oControl.Pages(oControl.value).ActiveControl
If TypeName(oControl) = "Frame" Then
Set oControl = oControl.ActiveControl
End If
ElseIf TypeName(oControl) = "Frame" Then
Set oControl = oControl.ActiveControl
If TypeName(oControl) = "MultiPage" Then
Set oControl = oControl.Pages(oControl.value).ActiveControl
End If
End If
In my opinion, the declaration of the oControl variable may point to the type MSForm.Control.Code:Dim oControl As MSForms.Control
Artik
It is in my case worse.
I have 5 pages and it so happens that on page 3 I have nested 2 frames as per the modified docm
It certainly does work for me on the other pages where I only have one frame
How can this be overcome.?