Results 1 to 6 of 6

Thread: [RESOLVED] Cut, Copy & Paste

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    UK
    Posts
    199

    Resolved [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.

  2. #2

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    UK
    Posts
    199

    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

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    UK
    Posts
    199

    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?

  6. #6

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
  •  



Click Here to Expand Forum to Full Width