I am using some vba code (see below) to put some data into the clipboard for pasting elsewhere.
But it seems to fail sometimes, I think it fails when the data is too long.
Is there a maximum?
The code below fails on the stmt, "DoCmd.RunCommand acCmdCopy"
No specific error msg, just the dreaded "Microsoft Access Must Close...."
It seems to happen when the length of the textbox is over 1000 characters.
I tried inserting some DoEvents statements, but it made no difference.
Suggestions?
Thanks,
Fred
Private Sub btnCopy_Click()
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblLogs", dbOpenDynaset, dbSeeChanges)
If rst.RecordCount = 0 Then
rst.Close
Set rst = Nothing
MsgBox "No Incidents"
Exit Sub
End If
rst.MoveFirst
' txtClipboard is a textbox with Visible=False
' 1. Data is copied into textbox
' 2. Textbox is made visible, so it can accept focus
' 3. Entire contents of textbox are selected
' 4. Contents copied into clipboard
' 5. Focus is moved back to the button
' 6. Textbox is re-hidden
Me.txtClipboard = Null
Do Until rst.EOF
Me.txtClipboard = Me.txtClipboard & "Incident# " & Nz(rst!Inc, "None") & vbCrLf
Me.txtClipboard = Me.txtClipboard & "Begin Date/Time: " & Format(rst!BegDateTime, "mm/dd/yyyy hh:nn ampm") & vbCrLf
Me.txtClipboard = Me.txtClipboard & "End Date/Time: " & Format(rst!EndDateTime, "mm/dd/yyyy hh:nn ampm") & vbCrLf
Me.txtClipboard = Me.txtClipboard & "Beat: " & rst!Beat & vbCrLf
Me.txtClipboard = Me.txtClipboard & "Location: " & rst!Loc & vbCrLf
Me.txtClipboard = Me.txtClipboard & "Neighborhood: " & rst!Hood & vbCrLf
Me.txtClipboard = Me.txtClipboard & "Inc Type: " & rst!IncType & vbCrLf
Me.txtClipboard = Me.txtClipboard & "Synopsis: " & rst!Synopsis & vbCrLf
Me.txtClipboard = Me.txtClipboard & "Watch Cmdr Contact: " & rst!WCContact & vbCrLf
Me.txtClipboard = Me.txtClipboard & " " & vbCrLf
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Me.txtClipboard.Visible = True
Me.txtClipboard.SetFocus
Me.txtClipboard.SelStart = 0
Me.txtClipboard.SelLength = Len(Me.txtClipboard)
DoCmd.RunCommand acCmdCopy
Me.btnCopy.SetFocus
Me.txtClipboard.Visible = False
MsgBox "Clipboard Contents Are Set"
End Sub