kevin33809
asked on
"Run-time error 521 - Cannot open clipboard"
I'm working on a program that allows me to copy a few selected records of a listbox to the Clipboard, but when I try to copy the whole list of 1017 records. I get the following error --"Run-time error 521 - Cannot open clipboard". See code below where the alleged error occurs.
Some of the things that I've tried to help the Clipboard along are -- 1. using a Sleep function to placate the process for a few seconds so Clipboard could populate. I've also tried the, 2. DoEvents to allow processing while Clipboard populates. Neither works. The error seems to occurs at the following line -- Clipboard.SetText.
Any help would be appreciated. Thank you.
Some of the things that I've tried to help the Clipboard along are -- 1. using a Sleep function to placate the process for a few seconds so Clipboard could populate. I've also tried the, 2. DoEvents to allow processing while Clipboard populates. Neither works. The error seems to occurs at the following line -- Clipboard.SetText.
Any help would be appreciated. Thank you.
'Export from Whole Grid in TXT TAB Format to Clipboard
If optRange(0).Value = True And optFormat(0).Value = True And optTarget(0).Value = True Then
If chkHdrs.Value = 1 Then
For j = 0 To tdbGrid.Columns.Count - 1
cs = IIf(tdbGrid.Columns(j).Caption & "" = "", "", tdbGrid.Columns(j).Caption)
strTemp = strTemp & cs & vbTab
Next
strTemp = strTemp & vbCrLf
End If
If xFilter.Count(2) > 0 Then
For n = 0 To xFilter.UpperBound(1)
For j = 0 To xFilter.UpperBound(2)
cs = IIf(xFilter(n, j) & "" = "", "", xFilter(n, j))
strTemp = strTemp & cs & vbTab
Next
strTemp = strTemp & vbCrLf <<< Accumulated records
Clipboard.Clear <<<< Clear clipboard
Clipboard.SetText strTemp, vbCFText <<< populate clipboard. Error occurs here.
Next
Else
For n = 0 To xda.UpperBound(1)
For j = 0 To xda.UpperBound(2)
cs = IIf(xda(n, j) & "" = "", "", xda(n, j))
cs = Replace(cs, vbLf, vbLf & String(j, vbTab))
strTemp = strTemp & cs & vbTab
Next
strTemp = strTemp & vbCrLf <<< Accumulated records
Clipboard.Clear <<<< Clear clipboard
Clipboard.SetText strTemp, vbCFText <<< populate clipboard. Error occurs here.
Next
End If
Sleep 10000 <<< Wait for 10 seconds.
MsgBox "Data copied successfully to clipboard", vbExclamation, "Exporting Data..."
End If
Runtime-error-521.jpg
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to be of service... :-)
ASKER
'Export from Whole Grid in TXT TAB Format to Clipboard
If optRange(0).Value = True And optFormat(0).Value = True And optTarget(0).Value = True Then
If chkHdrs.Value = 1 Then
For j = 0 To tdbGrid.Columns.Count - 1
cs = IIf(tdbGrid.Columns(j).Cap
strTemp = strTemp & cs & vbTab
Next
strTemp = strTemp & vbCrLf
End If
If xFilter.Count(2) > 0 Then
For n = 0 To xFilter.UpperBound(1)
For j = 0 To xFilter.UpperBound(2)
cs = IIf(xFilter(n, j) & "" = "", "", xFilter(n, j))
strTemp = strTemp & cs & vbTab
Next
strTemp = strTemp & vbCrLf
Next
Clipboard.Clear
Sleep 1000
Clipboard.SetText strTemp, vbCFText
Else
For n = 0 To xda.UpperBound(1)
For j = 0 To xda.UpperBound(2)
cs = IIf(xda(n, j) & "" = "", "", xda(n, j))
cs = Replace(cs, vbLf, vbLf & String(j, vbTab))
strTemp = strTemp & cs & vbTab
Next
strTemp = strTemp & vbCrLf
Clipboard.Clear
Sleep 1000
Clipboard.SetText strTemp, vbCFText
Next
End If
MsgBox "Data copied successfully to clipboard", vbExclamation, "Exporting Data..."
End If