By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,510 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,510 IT Pros & Developers. It's quick & easy.

Clear clipboard use to fix PasteAppend error

P: 6
I am using the following routine to copy a row and append it to the table. The user then changes appropriate information relevant to the current date.

I keep getting an error when using CopyPA macro as posted. The error: Action failed Condition: True Action Name: RunCommand Arguments: 38.

When I halt it, the message "the command or action 'PasteAppend' is not available now". Sometimes it will work, but then other times, I get the error. From what I found while searching for this error, the clipboard is full at the time and cannot accept anything more. I attempted to add a routine to clear the clipboard, and that doesn't seem to be working. Perhaps I don't have it defined correctly. Could someone look at this and tell me if I have the functions/sub correctly defined in the right location? Can you tell me why I am getting the error and if I am on the right track? I am using Access 2003.
CopyPA macro:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  RunCommand SelectRecord
  3.  RunCommand Copy
  4.  RunCommand PasteAppend 
VBA:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub CopyRecord_Click() 
  3. On Error GoTo Err_CopyRecord_Click
  4.  
  5. Dim stDocName As String 
  6. stDocName = "CopyPA" 
  7. DoEvents
  8. DoEvents
  9. DoEvents
  10. DoEvents
  11. DoCmd.RunMacro stDocName
  12.  
  13. Exit_CopyRecord_Click: 
  14. Exit Sub
  15.  
  16. Err_CopyRecord_Click: 
  17. MsgBox Err.Description 
  18. Resume Exit_CopyRecord_Click
  19. End Sub 
Feb 29 '12 #1

✓ answered by NeoPa

Kent T:
I think it is rather caveman to put in several DoEvents
I agree. Without closer contact with the project it's hard to know how best to handle, but if a single one doesn't do it then I'd be looking to see why.

PS. Be careful of what you retro-fit to the question (Post #1). Where changes represent the question as it should have been, then retro-fit avidly. Where they represent progress in the thread, then it's not so good an idea. You're obviously someone who picks up ideas well, so I'm sure this will make sense to you.

PPS. Another idea to consider might be to avoid the use of macros entirely. I'm not a fan anyway, but if all is VBA then you can predict the flow of the code, whereas with macros calling code, that's less clear. Just a thought.

Share this Question
Share on Google+
11 Replies


NeoPa
Expert Mod 15k+
P: 31,186
The macro looks wrong to me. I don't work with macros ever anyway, but I somehow doubt what you have there makes any real sense. Multiple commands on the same line surely can't be right.

The code looks wrong in a number of places, but you should be able to see that for yourself if you follow the instructions in Before Posting (VBA or SQL) Code. If/when you have a situation with an error that isn't caused by easily avoidable errors (The link should help with that), then please post the details correctly as indicated and we'll see what we can do for you.
Feb 29 '12 #2

P: 6
Sorry, there were some formatting problems from pasting in the message. I have adjusted it. I will also look at the link provided. Thanks.
Mar 1 '12 #3

NeoPa
Expert Mod 15k+
P: 31,186
Good job :-)

Line #25 of your code is still suffering from being impossible code though. The linked article should help with that, but if you're still stuck when your code is valid then repost it and we can look into it for you.
Mar 1 '12 #4

P: 6
Fixed again. The problem seems to be that the clipboard in Windows cannot respond fast enough, so I am trying the clear clipboard method. Is it possible that I need to utilize a delay between the copy and the paste?
Mar 1 '12 #5

NeoPa
Expert Mod 15k+
P: 31,186
Try using DoEvents(). You can find all the details using Context-Sensitive Help.
Mar 1 '12 #6

P: 6
I will try that and see what happens.
Thanks for the suggestion.
Mar 2 '12 #7

NeoPa
Expert Mod 15k+
P: 31,186
You're welcome.

PS. I like the way you fix the problems when found, rather than adding extra posts that only tend to confuse people reading the thread.

PPS. To format code the best way, add the closing [/code] tag to the end of the last line rather than on the following one. It saves an empty line at the bottom ;-) Also, within [code] tags, spaces are always shown as is and are the same width as all other chars, so they can be used to tabulate data, whereas TAB chars are useless for that.
Mar 2 '12 #8

P: 6
Updated code to utilize DoEvents. I have multiple instances because when testing it several times in a row (clicking quickly), the same issue appears. However, in actual use, probably only one record will be copied in a session, so this may not occur. I think it is rather caveman to put in several DoEvents, but until I learn more, it may do. I will continue to test it and repost.
Mar 2 '12 #9

NeoPa
Expert Mod 15k+
P: 31,186
Kent T:
I think it is rather caveman to put in several DoEvents
I agree. Without closer contact with the project it's hard to know how best to handle, but if a single one doesn't do it then I'd be looking to see why.

PS. Be careful of what you retro-fit to the question (Post #1). Where changes represent the question as it should have been, then retro-fit avidly. Where they represent progress in the thread, then it's not so good an idea. You're obviously someone who picks up ideas well, so I'm sure this will make sense to you.

PPS. Another idea to consider might be to avoid the use of macros entirely. I'm not a fan anyway, but if all is VBA then you can predict the flow of the code, whereas with macros calling code, that's less clear. Just a thought.
Mar 2 '12 #10

P: 6
It's a good thought. I had it banging through my little brain all weekend, and dummy here found that the same commands are available in VBA that I was using in the macro. I have nixed the macro and changed the code to include DoCmd.RunCommand as needed. I was making it entirely too hard. Thanks for all your direction.
Mar 5 '12 #11

NeoPa
Expert Mod 15k+
P: 31,186
Good to hear :-) There's no reason everyone should have to learn all the same lessons from scratch.
Mar 5 '12 #12

Post your reply

Sign in to post your reply or Sign up for a free account.