Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2022
    Location
    Raleigh, NC
    Posts
    5

    VBA Can't copy contents of text field of last record on a subform to clipboard

    I have this VBA code that is driving me nuts! It seems right to me, but the clipboard is always empty:


    Me.[Case Attachments subform].SetFocus
    DoCmd.GoToRecord , , acLast
    Me![Case Attachments subform].Form![Doc Description].SetFocus


    Me![Case Attachments subform].Form![Doc Description].SelStart = 0 ' Start of the text
    Me![Case Attachments subform].Form![Doc Description].SelLength = Len(Me![Case Attachments subform].Form![Doc Description].Value) ' Entire length of the text
    DoCmd.RunCommand acCmdCopy


    I ran a checkpoint prior to the acCmdCopy and confirmed that the [Case Attachments subform].Form![Doc Description].Value is correct. How do i get the contents it has selected to the clipboard!!!

  2. #2
    Join Date
    Sep 2022
    Location
    Raleigh, NC
    Posts
    5
    Solved it! The beginning of the thread had this code:
    Set WshShell = CreateObject("WScript.Shell")
    Set oExec = WshShell.Exec("clip")
    Set oIn = oExec.stdIn

    Moving that code to be nested inside the If condition, made it so that the DoCmd.RunCommand acCmdCopy worked in the Else condition!
    Why, I don't know, but that was the issue.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by demaionewton View Post
    Solved it! The beginning of the thread had this code:
    Set WshShell = CreateObject("WScript.Shell")
    Set oExec = WshShell.Exec("clip")
    Set oIn = oExec.stdIn

    Moving that code to be nested inside the If condition, made it so that the DoCmd.RunCommand acCmdCopy worked in the Else condition!
    Why, I don't know, but that was the issue.
    Which you never showed.

    Always best to show all the code because of situations like this.
    Copy and paste as well, do not retype, as that just introduces other errors.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 15
    Last Post: 08-23-2021, 06:21 AM
  2. Replies: 1
    Last Post: 04-04-2018, 02:33 PM
  3. btn macro what can copy text to clipboard
    By TriFith in forum Import/Export Data
    Replies: 6
    Last Post: 07-01-2016, 02:45 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

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
  •  
Other Forums: Microsoft Office Forums