but when i reopen it nothing is updated
Are you looking in the right place for the new file? You are copying to E:\, not E:\Desktop where the file to be overwritten is located. Consider the security blocks you may have to deal with before going further. Permission denied sounds like you don't have the right to save to C:\, plus you also have to worry about the end user having the same problem. Then, there is the issue with copying a file from one place to another - Trusted Locations. Even on my home pc, if I copy a db from one folder to the other, I can get the warning that functionality has been disabled in the copied version. You should seek the support of your IT in setting up permissions, trusted locations, groups, or whatever else you need in order to make this work. As for the code, I just modified and tested to see what happens if I had the db open when trying to overwrite it because what I had was not meant to do that on an open file. So in the source file I coloured the detail section of the form that would enable this. In the target file, I clicked the button, then closed and reopened the form and it was now coloured. The code doesn't look that much different from what you have now, so I really think you have to deal with security issues first. However, to get a working version when you go back to work, try copying from one place to another where you are sure you have permissions on both. I also suggest that your code should loop through the forms and reports collections to see if any are open, and stop if they are. I would not gamble on what overwriting a db would do to open recordsets. It would be safer to get the user to do this and deal with any prompts that must be dealt with.
Code:
Private Sub cmdFileCopy_Click()
Dim fs As FileSystemObject
Dim SrceFile As String
Dim TargetFile As String
'Call a reusable function here to loop thru forms/reports??
' If function returns True, give message and exit this sub??
' I would then call Application.Quit after messaging they have to restart.
SrceFile = "C:\Users\Mypc\Desktop\TestFileHere\Example.accdb"
TargetFile = CurrentProject.Path & "\Example.accdb" 'file to be replaced
Set fs = New FileSystemObject
fs.CopyFile SrceFile, TargetFile, True
Set fs = Nothing
End Sub
Last edited by Micron; 01-09-2016 at 10:51 AM.
Reason: restart
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.