Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error closing form

Status
Not open for further replies.

hondaman2003

Programmer
Mar 3, 2008
202
US
I have a form in a database that gives the error "The command or action 'Copy' isn't available now" when exiting. Most people that use this form are fine, but some get this error message. It also only happens when exiting this specific form, not other forms. Can anyone help?
 
It would be easier if you would post the code that is throwing the error.
 
I agree, the trouble is there is no code that I can find that would cause this error. There is nothing under the exit button, there is nothing under form close event, there is nothing under the unload event, I cannot find a singe place that has code causing the problem.
 
If you show the code that runs when the form is being used maybe someone here can see something you are not.

What is the form used for?
 
Another question,

Do you have error trapping in all the subs and functions?

If so, that should point to the section of code that is casuing the problem.

If not, adding error trapping in each sub and function might help.
 
This form calculates a copay based on medical plan parameters. There are almost 1900 lines of code. It's a working form with no data from a table or query. Just a form with text boxes and check boxes. A copay is calculated based on what the user puts into the text boxes. Code is run based on events in each object.

The error only happens when the user clicks the exit button or clicks the "x" in the top right corner of the window.

If you could give me a hint on what "event" you want to see or some other thing I would be happy to show it to you.
 
Very good suggestion on the error trapping. I did add it to every function no matter how simple the function and it still does not catch it on these very few computers. On the other computers were it catches it they see the error "The command or action 'Copy' isn't available now
 
Have you done a search for "Copy" to see where and how many times it is used?

What happens to the inputs that are done once they are finished making all their entries?

1900 lines of code, hopefully not all in one sub.
 
I use the command "DoCmd.RunCommand acCmdCopy"

This command is only located in the "got focus" event of the text box that needs to be copied, then pasted in a different program.

The 1900 lines of code are in the various events of the object, and in a few separate subs that i created.
 
I'm sorry I didn't answer your second question. After the user inputs the last text box the form will notice that everything is needs to perform the calculation and generate a note explaining how the copay was calculated. Then the user can simply click the text box with with newly generated note and it will be automatically copied to the clipboard and ready to be pasted wherever the user needs to.

Is that what you were looking for?
 
That helps. I played around with it and so far have not been able to duplicate it.

How are you getting the information to where it is "Copy-able"?

This is what I used.

Code:
Private Sub cmdCopy_Click()
On Error GoTo ErrHandler
'On Error Resume Next
With Me.txtCopy
    .SetFocus
    .SelStart = 0
    .SelLength = Len(.Value)
End With
    DoCmd.RunCommand acCmdCopy
    
Exit Sub
ErrHandler:
    MsgBox "Error copying to the clipboard. Error # " & Err.Number & ", " & Err.Description, vbYesNo, "Error"
End Sub

I could throw an error if I left the textbox blank so I tossed in a "resume next" but that did not cause any problems.

I also opened the clipboard viewer to make sure everything was getting copied and so far, it all gets in.

("Start" "Run" "Clipbrd" to run the clipboard viewer in XP)

On the machines you are having trouble with, try watching to see if the information makes it into the clipboard before you close the form.
 
It also only happens when exiting this specific form, not other forms"

Is the Copy command used on other forms? This question comes up from time to time and usually the problem is that system assets aren't being released. Most of the times if the user exits Access, goes into, for example, Word, then tries a Copy and Paste they'll get the same error.They eventually simply have to reboots, which releases the memory.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
This error only happens when exiting this specific form. I have other forms that do this same copy function their is no problem. Below is the code for "got focus" on the text box that has this commmand. It simply says that if the text box get's the focus by either clicking on it or tabing down to it, it will see if it's blank, and if it's not, then copy the contents.

Private Sub Note1_GotFocus()
On Error GoTo ErrorHandle
If IsNull([Note1]) = False Then DoCmd.RunCommand acCmdCopy
Exit Sub
ErrorHandle:
ErrorHandling

End Sub
 
These questions are digging for info:

Did you check the clipboard to see if the information is there before the form closes?

Does some protion of the procedure try to copy a picture (or some type of file) or just text?

Is that all the error code you have because that will not tell you anything about the error?
 
The person using the form will click the text box so it will copy, then go to another program to paste it. After that they will go back to the database and close it. I have not specifically checked the clipboard since they are able to successfully paste the text into another program.

Only text in the text box is copied no pictures or anything like that.

That is the only error message I have.

I was able to come up with some more information. When I remove the code that copies the contents of the text box, the error does not happen. This forces the user to hightlight and copy the text manually.
 
You may like to try

If nz([Note1]) Then DoCmd.RunCommand acCmdCopy


Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
using the If nz([Note1]) Then DoCmd.RunCommand acCmdCopy
command doesen't fix the problem either.
 
using the If nz([Note1]) Then DoCmd.RunCommand acCmdCopy
command doesen't fix the problem either.

It's just another way to deal with NULL's

You never answered my question on your Error trapping.

Code:
Private Sub Note1_GotFocus()
On Error GoTo ErrorHandle
If IsNull([Note1]) = False Then DoCmd.RunCommand acCmdCopy
Exit Sub
ErrorHandle:
[COLOR=red]ErrorHandling[/color]

End Sub

Try mine and see what error number it gives you

Code:
ErrHandler:
    MsgBox "Error copying to the clipboard. Error # " & Err.Number & ", " & Err.Description, vbYesNo, "Error"

This gives you a number and description
 
Could you try using the OnEnter instead?

Max Hugen
Australia
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top