I Need Help (1 Viewer)

Kimbrainscan

New member
Local time
Today, 12:19
Joined
Jul 29, 2020
Messages
5
I want to put a backup button on the form which is found on the access main ribbon because i will hide the ribbon title bar.. please help...
 

Minty

AWF VIP
Local time
Today, 09:19
Joined
Jul 26, 2013
Messages
10,353
Backup ?
Sorry what command is back up, I don't see that option on the standard ribbon?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:19
Joined
Feb 28, 2001
Messages
26,996
I'm not sure you can do that from a form. You can do it from Access via the FILE tab, but that is not on the menu or ribbon.

I think if you want to do a backup, Access has to momentarily close the file to copy it - because MSACCESS.EXE is running as its own process and then your app is running as a second process. (You can verify this through Task Manager, which will show that Access has a child task which is named for the app file.) Anyway, my point is that if you wish to back up the app file, it cannot be open which means that form cannot be open to host a button.

I could be wrong, and would be willing to believe I am wrong - but at the moment I don't think I am.

However, did you literally mean "backup the database" or were you talking about another entity WITHIN the database being backed up. That would make a difference.
 

hbrehmer

Member
Local time
Today, 02:19
Joined
Jan 10, 2020
Messages
78
I wrote a code to create a backup file when the user exits the program. I have that on my Main Menu. It works beautifully. I have experienced lost data and corruption with databases in the past and I don't have access to our server to create an auto backup nightly. I know I will end up with a couple copies of the data when multiple people quit the program, but then I go back in to the file and delete the oldest ones and keep on the last save.

Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please read this for further information:-
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Please feel free to Remove this Comment

Code:
Private Sub Quit_And_Save_Click()
    Dim objFSO
    Dim sSourceFolder
    Dim sBackupFolder
    Dim sDBFile
    Const OVER_WRITE_FILES = True

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    sSourceFolder = "S:\File"
    sBackupFolder = "S:\File\Backup\"
    sDBFile = "O2S.accdb"

    'Copy the file as long as the file can be found
    If objFSO.FileExists(sSourceFolder & "\" & sDBFile) Then
        objFSO.CopyFile sSourceFolder & "\" & sDBFile, sBackupFolder & "\" & sDBFile, OVER_WRITE_FILES
    End If

    Set objFSO = Nothing
   
    DoCmd.Quit acPrompt
   
End Sub

As I've mentioned before, it's very helpful if you can enclose your code in code tags:- https://www.access-programmers.co.u...letes-of-data-from-field.312666/#post-1706375

This is the second time I've brought this to your attention. If there's a third time, then I will bring it to the attention of the forum moderators...
 
Last edited by a moderator:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:19
Joined
Feb 28, 2001
Messages
26,996
Actually, I was in error. I did some research and found a way to do this that might be more reliable.


There are two methods in this thread. The one that is really clever is to do a compact & repair but express a different file as the destination. Therefore, your backup is compacted as well as copied.

The other method is to create an empty database file and then iterate through the objects one at a time to copy them into the new target.
 

hbrehmer

Member
Local time
Today, 02:19
Joined
Jan 10, 2020
Messages
78
Please Use Code Tags
So sorry! I did not see this post. I wasn't aware of the Code Tags. No need to be rude with Large Red Font. I guess trying to help other people on this forum is not encouraged. I can leave.
 

Users who are viewing this thread

Top Bottom