Automating CompactRepair--"db in use" error

I ran the following line of code from a db, called "writer.db".

    Application.CompactRepair "projecttrack.mdb", "db1.mdb", True

It worked great, creating both the "db1.mdb" file and a log file.

I erased the db1.mdb & the log file, and tried to run it again, and it 
failed, giving the following error:

    "Runtime error 7866. 
    Microsoft cannot open the database because it is missing or opened 
exclusively by another user."

I've closed all my copies of Access and reopened them, tried running again 
and get the same error. The applications are on my desktop computer--no one 
else could possibly be using them. Why did it work once then stop working?

Many thanks,

Phil Freihofner
0
Utf
3/22/2010 9:15:01 PM
access.modulesdaovba 1670 articles. 0 followers. Follow

3 Replies
757 Views

Similar Articles

[PageSpeed] 19

Hi,
try to make a copy first, and then Compact a copy

-- 
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Phil Freihofner" <PhilFreihofner@discussions.microsoft.com> wrote in 
message news:341A6A68-A359-49C2-9AAB-EE1EE426629D@microsoft.com...
> I ran the following line of code from a db, called "writer.db".
>
>    Application.CompactRepair "projecttrack.mdb", "db1.mdb", True
>
> It worked great, creating both the "db1.mdb" file and a log file.
>
> I erased the db1.mdb & the log file, and tried to run it again, and it
> failed, giving the following error:
>
>    "Runtime error 7866.
>    Microsoft cannot open the database because it is missing or opened
> exclusively by another user."
>
> I've closed all my copies of Access and reopened them, tried running again
> and get the same error. The applications are on my desktop computer--no 
> one
> else could possibly be using them. Why did it work once then stop working?
>
> Many thanks,
>
> Phil Freihofner 

0
Alex
3/23/2010 8:16:35 AM
You can use this code to make a copy:
http://www.mvps.org/access/api/api0026.htm

-- 
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Alex Dybenko" <alexdyb@PLEASE.cemi.NO.rssi.SPAM.ru> wrote in message 
news:Oxuz#EmyKHA.1236@TK2MSFTNGP06.phx.gbl...
> Hi,
> try to make a copy first, and then Compact a copy
>
> -- 
> Best regards,
> ___________
> Alex Dybenko (MVP)
> http://accessblog.net
> http://www.PointLtd.com
>
>
> "Phil Freihofner" <PhilFreihofner@discussions.microsoft.com> wrote in 
> message news:341A6A68-A359-49C2-9AAB-EE1EE426629D@microsoft.com...
>> I ran the following line of code from a db, called "writer.db".
>>
>>    Application.CompactRepair "projecttrack.mdb", "db1.mdb", True
>>
>> It worked great, creating both the "db1.mdb" file and a log file.
>>
>> I erased the db1.mdb & the log file, and tried to run it again, and it
>> failed, giving the following error:
>>
>>    "Runtime error 7866.
>>    Microsoft cannot open the database because it is missing or opened
>> exclusively by another user."
>>
>> I've closed all my copies of Access and reopened them, tried running 
>> again
>> and get the same error. The applications are on my desktop computer--no 
>> one
>> else could possibly be using them. Why did it work once then stop 
>> working?
>>
>> Many thanks,
>>
>> Phil Freihofner
> 
0
Alex
3/23/2010 8:18:54 AM
I switched from using the Application.CompactRepair to 
dbEngine.CompactDatabase. The latter function seems to do the job.

I appreciate the code that was sent (as complex and unreadable as it was) 
for copying a database. At some point I might try to figure it out. But 
copying the database seemed like, at best, a clumsy workaround. There was no 
reason that I can see that a direct statement should not work!!

I would be interested in knowing why the dbEngine.CompactDatabase works in 
situations where the Application.CompactRepair does not. But since the latter 
seems more current, perhaps the first has been deprecated or is buggy?

Thanks,

PF



"Phil Freihofner" wrote:

> I ran the following line of code from a db, called "writer.db".
> 
>     Application.CompactRepair "projecttrack.mdb", "db1.mdb", True
> 
> It worked great, creating both the "db1.mdb" file and a log file.
> 
> I erased the db1.mdb & the log file, and tried to run it again, and it 
> failed, giving the following error:
> 
>     "Runtime error 7866. 
>     Microsoft cannot open the database because it is missing or opened 
> exclusively by another user."
> 
> I've closed all my copies of Access and reopened them, tried running again 
> and get the same error. The applications are on my desktop computer--no one 
> else could possibly be using them. Why did it work once then stop working?
> 
> Many thanks,
> 
> Phil Freihofner
0
Utf
3/25/2010 12:59:01 AM
Reply:

Similar Artilces:

Automating CompactRepair--"db in use" error
I ran the following line of code from a db, called "writer.db". Application.CompactRepair "projecttrack.mdb", "db1.mdb", True It worked great, creating both the "db1.mdb" file and a log file. I erased the db1.mdb & the log file, and tried to run it again, and it failed, giving the following error: "Runtime error 7866. Microsoft cannot open the database because it is missing or opened exclusively by another user." I've closed all my copies of Access and reopened them, tried running again and get the sam...