Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Posts
    1

    Run-time Error '2046' when using DoCmd.RunCommand acCmdCopy whilst browsing records

    I have a simple form in access.

    There is one field on the form , DocID, which has the name of a document. When the form is loaded, I want the docID to be copied onto the clipboard so the user can paste this into another program without having to do a manual keyboard or mouse routine. After doing the copy, it moves the focus to the next field where a user could paste his results.

    So, for the oncurrent event I wrote:

    'copy the doc id value to the clipboard

    DocID.SetFocus
    DoCmd.RunCommand acCmdCopy

    'Move focus to DocID1 field


    DocID1.SetFocus


    This works great if you acutally work with the record. No problems. The problem arises when/if the user scrolls through the records, instead of updating the record. Then I get the error:

    Run-time Error '2046':
    The command or action 'copy' isn't available now.

    When I hit debug, it goes to the line: DoCmd.RunCommand acCmdCopy

    Can anyone help me figure out why this doesn't work when you are browsing/scrolling through the recordset?

  2. #2
    RaMcHiP is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2009
    Posts
    4

    I am not 100% sure if this will work for you but give it a try

    I ran into a problem similar to yours with a form I created the way I got around it was to add the line Me.Requery before commiting any docmd. actions.. hopes this helps BTW you only need to do it once per set of related actions..

  3. #3
    thhui is offline Competent Performer
    Windows XP Access 2002 (version 10.0)
    Join Date
    Feb 2009
    Posts
    235
    Just ignore the err 2046.
    The code would still work.

    Use the following code if you like.

    Code:
     
    Private Sub Form_Current()
    'copy the doc_id value to the clipboard
    On Error GoTo errHandler
     
    If Me.NewRecord Then
     
    Else
      Debug.Print Me.doc_id.Value
      Me.doc_id.SetFocus
      DoCmd.RunCommand acCmdCopy
    End If
     
    errExit:
     
    Exit Sub
     
    errHandler:
    If Err.Number = 2046 Then
      Resume Next
    End If
     
    end sub

  4. #4
    TomatoJo is offline Novice
    Windows XP Access 97
    Join Date
    Mar 2010
    Posts
    2

    error 2465

    I'm trying to use this code but I get a diff error, namely 2465. But, instead of trying to use a field, I am trying to copy the contents of a string variable that I previously Dimentioned. My partial code is below:

    Code:
    Dim Site as string
    
     Site = rsNewData![Station] & ", " & rsNewData![SampleDate]
    
      MsgAnswer = MsgBox(ScoreName & ", " & Site, vbOKCancel)   ' for testing only
      
          With Me!Site
            .SetFocus
            .SelStart = 0
            .SelLength = Len(.Value)
         End With
      
         Me.Requery
        DoCmd.RunCommand acCmdCopy
    So, is there a way to copy the string variable result onto the clipboard?

  5. #5
    thhui is offline Competent Performer
    Windows XP Access 2002
    Join Date
    Feb 2009
    Posts
    235
    Try this if it works:-

    1)Set the variable value to a dummy textbox first.
    2)Then copy this textbox value by
    DoCmd.RunCommand acCmdCopy

    PS: Comment out "me.requery"

  6. #6
    TomatoJo is offline Novice
    Windows XP Access 97
    Join Date
    Mar 2010
    Posts
    2
    Thanks!

    But I actually came across another way that worked, but, like you said, I first had to create a dummy text box on my form.

    Code:
    Dim strToCopy As String
      strToCopy = rsNewData![Station] & "-" & month & year
    
      Screen.ActiveForm.txtCopy = strToCopy
      Screen.ActiveForm.txtCopy.SetFocus
    
      ' copy selected text to the clipboard
      DoCmd.RunCommand acCmdCopy

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

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2018, 05:24 PM
  2. Run time error '6': Overflow
    By wasim_sono in forum Access
    Replies: 0
    Last Post: 06-22-2007, 06:44 AM
  3. DoCmd.SendObject Help
    By bgreer5050 in forum Programming
    Replies: 0
    Last Post: 01-12-2007, 06:27 PM
  4. Run Time Error 424
    By ddog171 in forum Programming
    Replies: 3
    Last Post: 02-04-2006, 07:13 AM
  5. Replies: 1
    Last Post: 12-09-2005, 09:16 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