Results 1 to 4 of 4
  1. #1
    fredz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    19

    Copy To Clipboard - Max Length?

    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

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I would not expect your DB to crash but rather cause an exception. Perhaps it is a matter of allocated vs. available memory for your machine.

    I was able to send up to 4000 characters to the clipboard using the following function
    http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

    the function indicates a limit of 4096 characters

    Here is a sample DB I created to test. It includes a loop to concatenate characters until the Len() function determines it is time to Exit Do. You may want to employ such a loop with your DAO example. This way, you could enumerate records within the recordset and index the record that causes your string to reach 4000 characters. With that information, you can call the copy to clipboard function for each block of 4000, revisiting the DAO recordset for each, consecutive, block of 4000.
    Attached Files Attached Files

  3. #3
    fredz is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    19
    Thank You ItsMe.
    I think I found the issue. Interesting.

    I was using the following code to select the entire contents of the textbox.
    Me.txtClipboard.SelStart=0
    Me.txtClipboard.SelLength = Len(Me.txtClipboard)

    But I found that wasn't necessary if the application option "Behavior Entering Field" was set to "Select Entire Field".
    So I removed those two lines of code and everything works fine. Even with 8000 characters in the textbox.

    Now, in case the user has their option set differently, I inserted this line of code:
    Application.SetOption "Behavior Entering Field", 0

    Things are looking good so far....
    Fred

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It is good that you were able to isolate what was limiting the length of the string, the textbox control methods. Thanks for posting the information.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Copy items in a column to the clipboard
    By kevinscomp in forum Access
    Replies: 1
    Last Post: 08-07-2013, 06:57 PM
  2. Replies: 2
    Last Post: 12-05-2012, 09:39 PM
  3. Replies: 4
    Last Post: 06-21-2012, 11:43 AM
  4. Use VBA to copy table contents to the clipboard?
    By Deutz in forum Programming
    Replies: 3
    Last Post: 10-21-2010, 10:59 PM
  5. Replies: 1
    Last Post: 03-13-2010, 08:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums