473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Trying to copy and overwrite a file

Having issues of users leaving excel workbooks that contain pivot tables linked to a db open, users are located all over the region so it is not as simple as walking around the office asking everyone to close out their files. I am trying to write a sub to copy and paste the newest version of my db over the old even while there are active connections, is there any way to force this? Currently my code is a simple

Expand|Select|Wrap|Line Numbers
  1. FileCopy "S:\path\x.mdb", "S:\path2\x.mdb"
Obviously if a file pointing to this db is open it throws error 90. Is there any way to either

1) kill connections to the db or
2) force the paste anyway?

Thanks in advnace for any insight, havn't found answers anywhere!
Dec 18 '13 #1

✓ answered by pegicity

UPDATE:

I found that by using a holding database that is simply a mirror of the master file (but all tables are smiply linked tables to the master file) I can freely update the source, which in turn updates the linked database holding file which is now the database that excel locks. Sure it is bush league, but it works!

Thanks to everyone who took the time to take a look. Yes I know this is a terrible way to run things but re-organizing the reporting unit is beyond my pay grade.

13 3720
xzorxx
12
you can make your db multiple, so more than one person can use it at same time
from tools go to option then advance option you will find something about default open change it to from private to shared
good luck
Dec 19 '13 #2
zmbd
5,501 Expert Mod 4TB
@xzorxx: if more than one can open then it is already in a shared state.

@pegicity: have you tried to open a normal Access session on the file? Depending on recordlocks, you should be able to alter the data directly from Access. Then the users when they refresh the pivot tables should pull from the new dataset.
Dec 19 '13 #3
NeoPa
32,556 Expert Mod 16PB
It's common practice to allocate a separate front end to each user. This is because of this, and other similar, problems involved with multiple users accessing the same database file directly.

I suspect you would find this approach gives you fewer problems.
Dec 19 '13 #4
zmbd
5,501 Expert Mod 4TB
Neo, I think that's already happening... just in excel not access.
IF they use the ribbon/data approach in excel to the tables then the db file can be locked, even from an Access front end as the connection default is shared deny write.

What They have to do in excel is:
File Open - Show All Files
Select the Access DB
In the advanced connections set share deny none
The connection string looks like this:
(sorry, not sure how to step this... yet)
Expand|Select|Wrap|Line Numbers
  1. Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Documents and Settings\z\My Documents\MS_Database_Projects\BytesWork\Bytes_peopletemplate.accdb;Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Engine Type=6;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False
The table is opened in a worksheet and there you have it... change the settings to refresh in background and set the timer to 5 or 15 or 60 minutes as you desire.
You can then use this table/worksheet as one would for any other operation such as a pivot table.

Then Access program can get at the data too... (well so can everyone).
Dec 19 '13 #5
Thanks for helping me out everyone, unforetunetly Zmbd's answer (while correct) isn't exactly what I was looking for.

Let me re-describe the situation. I am in the reporting unit for a company, my entry level job is to maintain a series (few dozen) of databases that the financial managers point to with excel pivot tables (to use Cognos or a similar SAP product would cost millions to set up and maintain, and the company doesn't find it worth while).

So, while your solution is correct, it isn't really feasable for me, as I have no idea how many reports have been created for each database. As you know it is relatively easy to create a pivot table pointed to a shared db. What I really need is some way to force an unlock from the db end of things.
Dec 19 '13 #6
zmbd
5,501 Expert Mod 4TB
Yes, I understand your situation, no need to re-describe.

If each user gets to create their own worksheet to pull the data, then you maybe out of luck as there is NO built in method to force a user to close the connection to an Access database.

Your only hope is to have IT force log them off. This may corrupt your data so be sure to have backups!
Dec 19 '13 #7
UPDATE:

I found that by using a holding database that is simply a mirror of the master file (but all tables are smiply linked tables to the master file) I can freely update the source, which in turn updates the linked database holding file which is now the database that excel locks. Sure it is bush league, but it works!

Thanks to everyone who took the time to take a look. Yes I know this is a terrible way to run things but re-organizing the reporting unit is beyond my pay grade.
Dec 19 '13 #8
zmbd
5,501 Expert Mod 4TB
Hmmm... learned something new!

How is the performance? Are the end user's seeing a lag in the data updates? With a double link (main-db>mirrored-db>excel) each time they want data, the user re-queries the link, which results in the mirrored-db re-quering its link.
Dec 19 '13 #9
Thankfully as this is just a reporting unit, the tables never get above 200 or 300K records as opposed to our SAP database that tracks actual transactions which gets to millions easily. So it might take 10 or 15 seconds, but seeing as it is better than tracking down a few hundred or so reports and trying to enforce a new connection precdure, I will take it.
Dec 19 '13 #10
NeoPa
32,556 Expert Mod 16PB
I reset the Best Answer as we generally don't encourage members to assign it to their own posts. That is to say, it's unusual that they have posted something new and not resulting mainly from others' work.

On this occasion, though, it seems it does make sense to assign that post as Best answer, so I have redone it for you.

BTW. Good thinking. Clever approach.
Dec 19 '13 #11
@NeoPa sorry about that was my first time actively taking part in this sub!

If it confuses anyone else why Excel would want to lock a file even when it is not being actively used (in this case, from a refresh point until the workbook is closed) I have found a way to ensure this does not happen. Now for me this was not an option as mentioned.

There are multiple way to select data sources for a pivot table in Excel. If you use the simple "Insert > Pivot > external data source" and attempt to link in the way I have used in this thread, you will NOT find the linked tables (previously created files will still find them just fine, but new ones will not). You will need to create a SELECT query that selects the entire table and point your pivot at that. This results in the same sort of file locking I was having problems with, but with this holding database you will be fine.

If you are the one creating and disseminating the reports, or are teaching the users how to create their own, there is another way to create a pivot table that points to your access database that will NOT keep the file locked after the refresh is completed. Under the Data ribbon you will find "From Other Sources" and then "From Microsoft Query". Should you point at the access database this way the file lock will not be an issue, you can over-write the database at will no matter how many reports are currently open and linked to it.

Why? Well I am sure Neo or Zmbd can explain it better but I will show you the difference in coding when I record the macro.

For the first import method it looks like this:

Expand|Select|Wrap|Line Numbers
  1. Workbooks("Test.xlsx").Connections.Add _
  2. "<DATA CONNECTION NAME>, """" , " & _
  3.       " Array( " & _
  4.         "OLEDB; Provider=Microsoft.ACE.OLEDB.12.0;" & _
  5.         "Password="""";User ID=Admin;" & _
  6.         "Data Source=S:\<DATABASE>.mdb;Mode=Share Deny Write;" & _
  7.         "Extended Properties="""";Jet OLEDB:System database="""";" & _
  8.         "Jet OLEDB:Registry Path="""";" & _
  9.         "Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;" & _
  10.         "Jet OLEDB:Database Locking Mode=0; Jet OLEDB:Global Partial Bulk Ops=2;" & _
  11.         "Jet OLEDB:Global Bulk Transactions=1; Jet OLEDB:New Database Password=""""; " & _
  12.         "Jet OLEDB:Create System Database=False; " & _
  13.         "Jet OLEDB:Encrypt Database=False; " & _
  14.         "Jet OLEDB: Don't Copy Locale on Compact=False; " & _
  15.         "Jet OLEDB:Compact Without Replica Repair=False; " & _
  16.         "Jet OLEDB:SFP=False; " & _
  17.         "Jet OLEDB:Support Complex Data=False; " & _
  18.         "Jet OLEDB:Bypass UserInfo Validation=False), " & _
  19.      "Array(""<NAME OF QUERY/TABLE IN DATABASE>""), 3 " & _
  20.      "ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, " & _
  21.      "SourceData:= ActiveWorkbook.Connections(""<NAME OF CONNECTION>""), " & _
  22.      "Version:=xlPivotTableVersion14).CreatePivotTable " & _
  23.      "TableDestination:=""Sheet1!R2C1"", " & _
  24.      "TableName:= ""PivotTable8"", " & _
  25.      "DefaultVersion:=xlPivotTableVersion14"
(Really sorry for the awful code, it IS a recorded macro after all) You can see it uses the OLEDB and that nasty Share Deny Write Zmbd mentioned. BUT the second method looks like this when recoreded:

Expand|Select|Wrap|Line Numbers
  1. Workbooks("Test.xlsx").Connections.Add "Query from MS Access Database3", "", _
  2.         Array(Array( _
  3.         "ODBC;DSN=MS Access Database;DBQ=S:\<DATABASE.mdb>;DefaultDir=S:\;DriverId=25;FIL=MS Access;MaxBuf" _
  4.         ), Array("ferSize=2048;PageTimeout=5;")), Array( _
  5.         "SELECT <DATABASE>.Division" & Chr(13) & "" & Chr(10) & "FROM `S:\DATABASE.mdb`.<TABLE IN DATABASE> <TABLE IN DATABASE>" _
  6.         ), 2
  7.     ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
  8.         ActiveWorkbook.Connections("Query from MS Access Database3"), Version:= _
  9.         xlPivotTableVersion14).CreatePivotTable TableDestination:="Sheet1!R1C1", _
  10.         TableName:="PivotTable7", DefaultVersion:=xlPivotTableVersion14
  11.  
  12.  
please note anything <IN CAPITALS BETWEEN THESE SIGNS> was changed for security reasons.

Short and clean (well relatively) with no write lock. As far as I can surmize from research OLEDB is simply a newer import standard that allows a wider variety of data sources, but default when importing this way (the ribbons I already described) it defaults to a Share Deny Write, an expression not available/used when the ODBC is called. I am SURE this isn't all right, but the end result is what matters most to me, and changing the connection method is easier than remembering to edit out the Share Deny Write each time.
Dec 19 '13 #12
NeoPa
32,556 Expert Mod 16PB
@NeoPa sorry about that was my first time actively taking part in this sub!
As I say, apologies not required. In this case it became clear that what you posted was very much worthy of being flagged as a Best Answer. You've actually provided a great deal of helpful information in this thread. I'm sure many members (of this forum and the public) will come across this thread in future and find it very helpful. Your further explanations give it even greater value.
Dec 19 '13 #13
Timoo
1
Indeed I came across this post and found it very interesting.
The linking is indeed a clever solution to de-attach your master data.

And the querying in Excel: I did not even know this option!
Clever guy you are :-)
Jul 9 '14 #14

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

Similar topics

2
by: Severin Ecker | last post by:
hi! i'm trying to copy a file with the std::copy function but my problem is, that whitespaces are discarded. could anyone tell me how i can just copy all the characters that are in the...
6
by: Tom | last post by:
I am having trouble when I read a file and another process is trying to update it. So I need a rountine to copy a file in asp.net. Can anyone assist? Thanks Tom
2
by: Shayer | last post by:
Hello I want to copy a file from server to client machine. How can i do that. I may have to use byte stream but how can i do that . Pls tell me THanks
3
by: Divya | last post by:
Hello, I am trying to copy a file from one domain to another. I have the username and password of the destination domain. I tried a few approaches - 1. Using the Impersonator Class -...
3
by: Kenneth H. Brannigan | last post by:
Hello, I have a FileSystemWatcher looking at a particular directory. When I copy a large file (750 MB) to this directory I receive multiple Change events. I am fine with this but when I call...
3
by: Christopher Lusardi | last post by:
If I want to copy one file to another how do I do that? I want to do this even if the second file already exists. Thanks, Christopher Lusardi
4
by: Thelma Lubkin | last post by:
I need to copy a file in a VBA module of an Access form, and I haven't been able to find out how to do it: just cp /Path1/file1 /Path2/file2 Please show me how to do this in VBA for Windows....
1
by: friglob | last post by:
i would need help with creating some cURL code... $old_file = "http://my_host.com/images/test.jpg"; $new_destination = "http://some_other_host.com/archived_images"; i was trying to create a...
0
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I am trying to install IIS but ran into the following problem. I have installed xp service pack 2 and am trying to install IIS using the add windows component feature but get the error (setup...
3
by: dmorand | last post by:
I'm trying to copy a file which is located on my C drive over to a network path. I'm getting the error below when trying to perform the copy. The file C:\query.sql does exist on my C drive so I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.