Is there any code that will close the db and same can be copeid samewhere?

Ashfaque

Search Beautiful Girls from your town for night
Local time
Today, 20:41
Joined
Sep 6, 2004
Messages
897
Hi,

I am looking for the code that will close the current db and copy the same db to a particular folder.

Is there anything like?

Regards,
Ashfaque
 
Why do you need? I have code that checks for version and if there is newer, copies revised frontend to user local drive. Worked until IT modified permissions so files can no longer be programmatically copied.
Code:
Private Sub Form_Load()
       
'Check for updates to the program on start up - if values don't match then there is a later version
If Me.tbxVersion <> Me.lblVersion.Caption Then
    'because administrator opens the master development copy, only run this for non-administrator users
    If DLookup("Permissions", "Users", "UserNetworkID='" & Environ("UserName") & "'") <> "admin" Then
        'copy Access file
        CreateObject("Scripting.FileSystemObject").CopyFile _
            gstrBasePath & "Program\Install\MaterialsDatabase.accdb", "c:\", True
        'allow enough time for file to completely copy before opening
        Dim Start As Double
        Start = Timer
        While Timer < Start + 3
            DoEvents
        Wend
        'load new version - SysCmd function gets the Access executable file path
        'Shell function requires literal quote marks in the target filename string argument, apostrophe delimiters fail, hence the quadrupled quote marks
        Shell SysCmd(acSysCmdAccessDir) & "MSAccess.exe " & """" & CurrentProject.FullName & """", vbNormalFocus
        'close current file
        DoCmd.Quit
    End If
Else
    'tbxVersion available only to administrator to update version number in Updates table
    Me.tbxVersion.Visible = False
    Call UserLogin
End If

End Sub
 
Thanks June7,

This kind of code I have and working very well. This code is to use on open startup form that will check the newer version and will pick the newer version from a perticular folder. I need the code lines to copy the db to that particular folder once I modify the working db

But the problem is such kind of vba code that will run at db closing time and once db closed nothing will be executed.

So it might be done from other db to copy the required db copying and storing somewhere.

Any other thought?
 
Why?,
Just wait until the user opens their FE, and then copy it then?
 
Sounds like you just need a backup procedure.
To ensure it runs before closedown, add it to the Form_Unload event of a hidden form that loads at startup & runs in the background whilst your databasse remains open. This guarantees the procedure will be the last code to run before the app closes (unless it crashes or is closed forcibly)
If you only want it to run when your database changes, then use a boolean variable as a flag to indicate whether or not the backup needs to be run.
However, is it really worth all that effort? Just save a backup copy when you make changes
 
Here's sample code that I use. Read the instructions because several objects are involved and you need to know what to copy to your own application and what to change.

The object of the backup is to back up the DEVELOPER'S copy of the FE so to be effective, you should close your FE at least once every hour to minimize loss. Backups from the same day are numbered incrementally. Typically, I let the backups accumulate for a few weeks and then delete the oldest copies.

In order to not bother the users, I hard code the developer's UserName. You can do what you want but since I never, ever want to back up the user copy, I find this to be the best method. That way, when the database closes, if it is "me", I get a prompt to ask if I want to save the FE. You can eliminate the prompt if you prefer and backup after every close (as long as you are the UserName) if you prefer.

This version backs up the entire db. I have a different version that exports all objects except tables to text. This has saved my bacon on multiple occasions when the db got corrupted. It is currently not included in this sample db but I am planning on doing that when I get some time. For now, the sample does what you are asking for. Just follow the directions and don't forget to pre-make the backup directories.
 

Attachments

Users who are viewing this thread

Back
Top Bottom