?
Solved

MS Access 2007 acCmdCopy not working

Posted on 2012-04-02
9
Medium Priority
?
1,381 Views
Last Modified: 2012-04-15
Hi,
Hope you can help.  Have Access 2007, just upgraded to Win 7.  This code was working under XP Pro now gives" Can't copy right now" - Error 2046. Here is the code. How do I handle this?

Thanks

   Dim vRenFile As String
   Dim vWho

   vWho = Nz(Forms![Contact Details]![FROM WHO].Column(1))
   vRenFile = Format$(Date, "yymmdd")

  'Debug.Print vRenFile
   vRenFile = vRenFile + " " + Nz(Forms![Contact Details]![Last Name]) + " " + Nz(Forms![Contact Details]![First Name]) + " Dog-" + Nz(Forms![Contact Details]![Dog Name]) + " FR-" + vWho + ".jpg"
       Forms![Contact Details].WorkSpace = "C:\Documents and Settings\David Schmucker\My Documents\My Dropbox\1-1 SDT Photo Master\" & vRenFile

  Forms![Contact Details]!WorkSpace.SetFocus
   DoCmd.RunCommand acCmdCopy
       Forms![Contact Details].WorkSpace = ""
0
Comment
Question by:DavidWSchmucker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 85
ID: 37796164
There are many different reasons why the Clipboard is not available, so you really should not automate or use it for anything of importance (like copying data, or something of that nature). If the users need to copy data, have them highlight it and press Ctrl + C to cop and Ctrl + V to paste.

Hotkeys could be used, but there are issues with that as well (in fact, 2010 has some serious Hot Key issues when used with Tab controls).
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37796670
First, you coding is a bit "Loose"
A lot of things you "Got away" with in previous version of Access/Windows simply have been "tightende up and no longer work.

1.
 Dim vRenFile As String
 Dim vWho '? As What?
Please always explicitly set a dataype, else it will be a Variant

2.
<vRenFile = vRenFile + " " + Nz(Forms![Contact Details]![Last Name]) ...>
When concatenating in VBA, try to use the "&" instead of "+"
vRenFile = vRenFile & " " & Nz(Forms![Contact Details]![Last Name]) ...

3.
"WorkSpace" is a VBA keyword, please avoid using it for an object names

4.
All in all you, ... may just need to save the current form record...
...
Forms![Contact Details]!WorkSpace.SetFocus
Docmd.RunCommand acSaveRecord    'Try adding this line
DoCmd.RunCommand acCmdCopy
...


JeffCoachman
0
 

Author Comment

by:DavidWSchmucker
ID: 37821484
Jeff, Thanks for the response.

I've selected simpler to get a grasp on it.  I think I followed your instructions.  This code still doesn't work. Any ideas?

Private Sub Command314_Click()
Dim vEm1 As String
vEm1 = Nz(Forms![contact details]![E-mail Address])
   Forms![contact details].WorkSpace = vEm1
   Forms![contact details]!WorkSpace.SetFocus
   DoCmd.RunCommand acCmdSaveRecord
   DoCmd.RunCommand acCmdCopy

End Sub
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37826296
1. Please rename your "WorkSpace" object as not to be confused with the WorkSpace object in VBA...

2. Can that control/filed accept nulls?

3. Where are you running this cod from?
I see you are fully qualifying the form.
This is not needed if you are running this from the same form, ...you can use: Me.SomeControl

4. The Setfocus line is not really needed, try commenting it out.
0
 

Author Comment

by:DavidWSchmucker
ID: 37829006
Here is the latest iteration. No joy.

Dim vEm1 As String
vEm1 = Me.[E-mail Address]
  Me.[DumbTxt] = vEm1
   DoCmd.RunCommand acCmdSaveRecord
   DoCmd.RunCommand acCmdCopy

Was wondering if SENDKEYS could be used to do a CTRL C on the DumbTxt fld?

Any help is appreciated. Thanks.
0
 

Accepted Solution

by:
DavidWSchmucker earned 0 total points
ID: 37829096
Well I went the API route and it worked.  For the library reference here is the code from Access help.

How to: Send Information to the 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.




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.




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
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 37829482
So you were using Win 7 *64 Bit*?
0
 

Author Comment

by:DavidWSchmucker
ID: 37829514
No Win 7 - 32 bit.  I saw something that said the copy command only works if the entry behavior is select entire field.  Don't know if that is true or not.
0
 

Author Closing Comment

by:DavidWSchmucker
ID: 37848003
It worked
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question