Question Updating to Access 2010: 'Copy' isn't available now

Daveyk01

Registered User.
Local time
Yesterday, 18:14
Joined
Jul 3, 2007
Messages
144
Hello there,

It's been a while since I have been here, but here goes....

Cobverting our service database from Access to Access 2010 and there has been a few hurtles in the code (i.e., loss of calendar control - solved, Utility.MDS - still in flux, etc) and now this:

I have a convenience field showing a serial number. The user simply had to double click in the field to copy the serial number to the windows clip board. In Access 2000, here is the code that worked brilliently (probably got it from here):
Me.SerialNum.SetFocus
SendKeys "{End}" & "+{Home}", True
Sleep (500)
DoCmd.DoMenuItem acFormBar, acEditMenu, acCopy, , acMenuVer70

The sendkeys still works fine, the data in the field "SerialNum" gets highlighted.
But when the DoCmd line executes, I get the error:
"Runtime error '2046': The command or action 'Copy' isn't available now"

Any ideas?:confused::confused:
 
Okay, I did not find an answer to the Error, but I did find this in the help file and it works like a charm to send data to the Windows Clipboard:
Use the Windows API

To use Windows API calls to send information to the Clipboard, paste the following code into the Declarations section of a standard module.
VBA Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _ As Long Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) _ As Long Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _ ByVal dwBytes As Long) As Long Declare Function CloseClipboard Lib "User32" () As Long Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) _ As Long Declare Function EmptyClipboard Lib "User32" () As Long Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _ ByVal lpString2 As Any) As Long Declare Function SetClipboardData Lib "User32" (ByVal wFormat _ As Long, ByVal hMem As Long) As Long Public Const GHND = &H42 Public Const CF_TEXT = 1 Public Const MAXSIZE = 4096
The following procedure illusrtrates how to send information to the Clipboard.
VBA Function ClipBoard_SetData(MyString As String) Dim hGlobalMemory As Long, lpGlobalMemory As Long Dim hClipMemory As Long, X As Long ' Allocate moveable global memory. '------------------------------------------- hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1) ' Lock the block to get a far pointer ' to this memory. lpGlobalMemory = GlobalLock(hGlobalMemory) ' Copy the string to this global memory. lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString) ' Unlock the memory. If GlobalUnlock(hGlobalMemory) <> 0 Then MsgBox "Could not unlock memory location. Copy aborted." GoTo OutOfHere2 End If ' Open the Clipboard to copy data to. If OpenClipboard(0&) = 0 Then MsgBox "Could not open the Clipboard. Copy aborted." Exit Function End If ' Clear the Clipboard. X = EmptyClipboard() ' Copy the data to the Clipboard. hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory) OutOfHere2: If CloseClipboard() = 0 Then MsgBox "Could not close Clipboard." End If End Function

I still no why the docmd method no longer worked.
 
DoCmd.DoMenuItem is an OLD, OLD, OLD legacy code which has been replaced by the RunCommand items. To copy it would have been simple just to use:
Code:
DoCmd.RunCommand acCmdCopy
 
DoCmd.DoMenuItem is an OLD, OLD, OLD legacy code which has been replaced by the RunCommand items. To copy it would have been simple just to use:
Code:
DoCmd.RunCommand acCmdCopy

Thank you, I had tried that and got the same error with Access 2010.

The API Code, which I tried to upload and it looks like garbligoop, I see, worked great to copy any text to the Clipboard. Its a lot more work, but once that function is placed in a module somewhere, it works well.
 

Users who are viewing this thread

Back
Top Bottom