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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime error '2501' during CopyObject 1

Status
Not open for further replies.

wabtrainer

IS-IT--Management
Feb 4, 2002
66
GB
Is there any reason why I am getting this error now when it has worked before????
All I am doing is copying a table in the current database.
For example I have Parts table which when altered the user clicks a button to save it with a different name.
Heres the code:

newname = InputBox("Enter a name for the Parts list")

'***************************************************
'Keep a list of names
'add newname to list
'***************************************************
sqlstr = "INSERT INTO tblPartsListNames (TableName) " _
& "VALUES ( '" & newname & "') "
DoCmd.RunSQL (sqlstr)

DoCmd.CopyObject , newname, acTable, "Parts"

It has worked before but for some reason


If you want to be a bear:
Be a Grizzly!
 
I think that when a table exists with the same name as "newname", then you might get such error - but probably also a "The name you entered alredy exists..." message, no?

One possible difference, if you previously turned warnings off during the operation

[tt]DoCmd.Setwarnings False[/tt]

it might be that they are on now? If you turn warnings off prior to running your code, then remember to turn it on afterwards

[tt]DoCmd.Setwarnings True[/tt]

perhaps that's what's needed?

Roy-Vidar
 
Thanks for your ideas.
I have warnings set to false and there is no table with that name.
The code stops at the DoCmd.CopyObject method and reports
"Run-time error '2501':
The CopyObject action was canceled."
Is there any thing else I am missing?


If you want to be a bear:
Be a Grizzly!
 
I have done some testing and laughably the only time I get this error is if I name the table 'Test' or 'test'!!!!!
Any other name given seems to work ok.

Can any one shed some light on why this is occuring.

What a pain. OK so I can now trap this with something like:
If err.number = 2501 then
msgbox("Try again with different name!"), but it would be nice to understand why the error is occuring???????

Confused!


If you want to be a bear:
Be a Grizzly!
 
Roy
You sir, are a steely eyed missle-man!
I should have picked up on the fact. Yes I had a query called test and it was that fact that was causing the problem. Of course CopyObject was wondering which object!!!!
A fresh pair of eyes was all thats needed.

Serves me right for naming everything 'Test' when testing/debugging.

Many thanks!


If you want to be a bear:
Be a Grizzly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top