-
Nov 9th, 2011, 04:46 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Cut, Copy & Paste
Hi Guys
Im trying to use the following code to effectively do a edit menu -> Select All.
Code:
Screen.ActiveControl.SelStart = 0
Screen.ActiveControl.SelLength = Len(Screen.ActiveControl.Text)
if i replace screen.activecontrol with an exact textbox name, all is well, but with the code above i get the following message:
object doesn't support this property or method
What can I do to make the 'select all' code generic, to act upon any textbox, other than what I have done?
Thanks in advance.
-
Nov 9th, 2011, 06:17 PM
#2
Re: Cut, Copy & Paste
It depends how the code is used: if you do that when button is clicked then that button becomes an active control which doesn't support "text" property.
Hope that makes sense.
-
Nov 9th, 2011, 06:34 PM
#3
Thread Starter
Addicted Member
Re: Cut, Copy & Paste
Hmm... Thanks RhinoBull - it does make sense but......
I have cut, copy, paste & select all menu options on my MDI form, like notepad has for example.
The cursor is in the textbox, and then I click my menu option, therefore THAT becomes the 'ACTIVE CONTROL'.
How can I overcome this so that my menu options will work?
Im thinking that I will have to write the textbox control name to a global variable on textbox lostfocus to be able to address it directly from my menu.
However, this means that there will be a large amount of entries to add over multiple textboxes, which I would rather not do.
Is there a better way?
Thanks
-
Nov 9th, 2011, 06:44 PM
#4
Re: Cut, Copy & Paste
No, menus are different so in a nutshell it shoud work. Try the below sample:
Code:
Option Explicit
Private Sub mnuCopy_Click()
If TypeOf Form1.ActiveControl Is TextBox Then
Clipboard.Clear
Clipboard.SetText Form1.ActiveControl.Text
End If
End Sub
Now, try ctrl+v into any text editor.
edit: I just noticed that you're using Screen - try Actual Form Name instead.
-
Nov 9th, 2011, 07:04 PM
#5
Thread Starter
Addicted Member
Re: Cut, Copy & Paste
Yes that works.
I have found various other things though.
screen. blah does work. my issue lies here:
Code:
Screen.ActiveControl.SetFocus
Clipboard.SetText Screen.ActiveControl.SelText
whereas it should be:
Code:
Screen.ActiveControl.SetFocus
Clipboard.SetText Screen.ActiveControl.Text
I have found that there doesnt seem to be a 'SELTEXT' property.
How can I specify what text to copy, ie just the numbers from this string:
abc123456xyz
the selected text?
-
Nov 9th, 2011, 07:45 PM
#6
Re: Cut, Copy & Paste
If numerical part position is always consistent then use Mid function, otherwise you need to loop.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|