Avatar of ShawnGray
ShawnGray

asked on 

Copy .accdb in use

Access o365, VBA, copying a ".accdb" file to same location with a new file name.
The routine works unless someone is using that particular file.
Is it possible to get around that?

If the file is in use I get a runtime error 70 "permission denied".
If the file is not in use, it copies fine.
Microsoft 365Microsoft AccessVBA

Avatar of undefined
Last Comment
ShawnGray
ASKER CERTIFIED SOLUTION
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of ShawnGray
ShawnGray

ASKER

Thank you all, this is a BE file.  
So this must have changed from mdb to accdb.
If so, I'll find a workaround.
Thank you again
Avatar of ShawnGray
ShawnGray

ASKER

...one other thought; why can manually copy an .accdb file in use?
Only vba seems to have an issue with it.
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

Manual copy uses Windows, not Access/VBA.  Windows doesn't care about the lock file.
You might try using another technology such as the Win32 API or script to copy the file.
SOLUTION
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

The solution is what?.....
Avatar of ShawnGray
ShawnGray

ASKER

Mark,
That's awesome.  Perfect.
Really appreciate the help.
Shawn
Avatar of Robert Berke
Robert Berke
Flag of United States of America image

Keep in mind that copying an open Access file might give you a corrupted result.  Internal pointers may point to the wrong place,

Also, I am too late with for the following to be a solution, but it works.

Sub copy()
Dim str As String, pid As Long
Path = "C:\EFG Front Ends"
srcfile = "Front End Address Book.mdb"
tgtfile = "NewName.mdb"

str = "cmd.exe /s /k copy 'path\src' 'path\tgt'"
str = Replace(str, "path", Path)
str = Replace(str, "src", srcfile)
str = Replace(str, "tgt", tgtfile)
str = Replace(str, "'", Chr(34))
On Error Resume Next
Kill Path & "\" & tgtfile
On Error GoTo 0



pid = Shell(str, 0)

           
End Sub
Avatar of ShawnGray
ShawnGray

ASKER

Mark, I used your public function.
Rberke, thank you as well.  Haven't tried it but it looks helpful.
Avatar of Robert Berke
Robert Berke
Flag of United States of America image

Mark's solution is better than mine for copying a file.  Mine is more general and can be used for most Command Line functions.
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

You're welcome rberke.
As always, I learn a little bit from everyone who participates is these discussions.
Avatar of PatHartman
PatHartman
Flag of United States of America image

Sorry but it makes no sense to replace a copy of the BE while the file is open.  If the BE is never updated, at least open it as read-only.
Avatar of PatHartman
PatHartman
Flag of United States of America image

I'm not sure why you accepted all these comments as the answer.  The whole point of accepting an answer is to help others zero in on the solutions.  Rewarding experts for participating does not serve any purpose.
Avatar of ShawnGray
ShawnGray

ASKER

Pat,
originally those answers were accepted because I believed it was a final result.  Only after that did a solution to accomplish my objective present itself.
Regarding the 'makes no sense to replace a copy...', the logic behind this need was not disclosed.  Although it wasn't relevant to the objective, it does serve a purpose.
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo