Results 1 to 14 of 14

Thread: [RESOLVED] Copy to Clipboard error

  1. #1

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    535

    Resolved [RESOLVED] Copy to Clipboard error

    My latest app copies text to the clipboard. If I use this app exclusively, after about, say the 10th or 11th copy, I get the following runtime error:

    "Run-time error 521 - Cannot open clipboard"

    Any ideas on how to fix this? If you need the code that I'm using, it can be found on a previous post regarding the systray.
    Attached Images Attached Images  
    Last edited by mateo107; Nov 21st, 2005 at 07:44 PM. Reason: NOT RESOLVED


    -Matthew-

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,467

    Re: Copy to Clipboard error

    Try Clipboard.Clear every few iterations.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Copy to Clipboard error

    Quote Originally Posted by timeshifter
    Try Clipboard.Clear every few iterations.
    Yep, I think you may be clogging up the clipboard.

  4. #4
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Copy to Clipboard error

    Quote Originally Posted by timeshifter
    Try Clipboard.Clear every few iterations.
    not every few..every time you are going to change it, clear it.

  5. #5
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,467

    Re: Copy to Clipboard error

    that would be a good idea, wouldn't it? No confusion when getting stuff from it... Why didn't I think of that?

  6. #6

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    535

    Re: Copy to Clipboard error

    I figured as much... just wanted to check with ya'll since I'm new to using the clipboard in my app.

    You guys are the best! Thanks!


    -Matthew-

  7. #7

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    535

    Re: Copy to Clipboard error - NOT RESOLVED

    Before I copy anything to the clipboard, I run Clipboard.Clear.. and I still get this error... ANy Ideas?

    In Fact, here is the code:

    VB Code:
    1. Clipboard.Clear
    2. Clipboard.SetText RemindMe.List1.Text
    3. RemindMe.Text1.SetFocus


    -Matthew-

  8. #8
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,916

    Re: Copy to Clipboard error - NOT RESOLVED

    According to MSDN, this error means that the Clipboard has already been opened by another application.

    HTH
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  9. #9
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    376

    Re: Copy to Clipboard error - NOT RESOLVED

    What routine do you call that in? I can't re-create your error.

  10. #10

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    535

    Re: Copy to Clipboard error - NOT RESOLVED

    is there any way to "close" the clipboard before i send the data to the clipboard?


    -Matthew-

  11. #11
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,916

    Re: Copy to Clipboard error - NOT RESOLVED

    Quote Originally Posted by mateo107
    is there any way to "close" the clipboard before i send the data to the clipboard?
    Not that I'm aware of. Maybe the best solution would be to just trap the error and carry on
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    4.  
    5. Private Sub WriteToClipBoard()
    6.  
    7.     Dim retries As Integer
    8.    
    9.     On Error GoTo Clip_Error
    10.    
    11.     Clipboard.Clear
    12.     Clipboard.SetText RemindMe.List1.Text
    13.     RemindMe.Text1.SetFocus
    14.    
    15.     Exit Sub
    16.    
    17. Clip_Error:
    18.  
    19.     If Err = 521 Then
    20.         If retries > 10 Then
    21.             MsgBox "Unable to access clipboard" & vbCrLf & "Try again later"
    22.         Else
    23.             retries = retries + 1
    24.             Sleep 100
    25.             Resume
    26.         End If
    27.     Else
    28.         MsgBox Error$
    29.     End If
    30.        
    31. End Sub
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  12. #12

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    535

    Re: Copy to Clipboard error - NOT RESOLVED

    Clipboard.GetData is basically the paste function, right?


    -Matthew-

  13. #13

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    535

    Re: Copy to Clipboard error - NOT RESOLVED

    OKAY - the problem is now resolved... apparently, running the Clipboard.clear and clipboard.settext without a pause in between is causing the problem.... I added a sleep command = 100 and the problem disappeared! thanks to all who helped me track down this solution


    -Matthew-

  14. #14
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Copy to Clipboard error - NOT RESOLVED

    Quote Originally Posted by mateo107
    OKAY - the problem is now resolved... apparently, running the Clipboard.clear and clipboard.settext without a pause in between is causing the problem.... I added a sleep command = 100 and the problem disappeared! thanks to all who helped me track down this solution
    weird..never heard that but will sure remember the solution..glad we could help!

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