[AccessD] Command to save the database

Bill Benson bensonforums at gmail.com
Tue Jun 16 09:19:29 CDT 2015


Found what I was looking for.

         RunCommand acCmdSave

Here is the completed routine; If you use a startup form (or open another
invisible form from code on your current startup form), and run this
routine from a timer, I think it is safe to say one has a pretty robust
backup routine, which is useful to a developer. Probably not something to
keep in place for runtime versions or in situations where the database is
very large.

If someone sees anything to modify, that would be helpful - thanks again.

Sub SaveMe()
Dim objFSO As Object
Dim objFSOFolder As Object
Dim strThisApp As String
Dim iSpace As Long
Dim iNumeric As Long
Dim TheMax As Long
Dim strLookForNumeric As String
Dim FIL As Object
Dim strStartText  As String
Dim strPath As String

strThisApp = Mid(CurrentDb.Name, InStrRev(CurrentDb.Name, "\") + 1)
strThisApp = Left(strThisApp, InStrRev(strThisApp, ".") - 1)
Set objFSO = New FileSystemObject
strPath = Environ("USERPROFILE") & "\My Documents"
On Error Resume Next
Set objFSOFolder = objFSO.GetFolder(strPath & "\Backups for " & strThisApp)
If objFSOFolder Is Nothing Then
    Set objFSOFolder = objFSO.GetFolder(strPath & "\Backups for " &
strThisApp)
    If objFSOFolder Is Nothing Then
        Set objFSOFolder = objFSO.CreateFolder(strPath & "\Backups for " &
strThisApp)
    End If
End If
For Each FIL In objFSOFolder.Files
    If InStr(FIL.Name, "Backup No ") > 0 And InStr(FIL.Name, strThisApp) >
0 Then
        strStartText = Mid(FIL.Name, Len("Backup No ") + 1)
        iSpace = InStr(strStartText, Chr(32))
        strLookForNumeric = Left(strStartText, iSpace - 1)
        On Error Resume Next
        iNumeric = CLng(strLookForNumeric)
        If iNumeric > TheMax Then
            TheMax = iNumeric
        End If
    End If
Next
objFSO.CopyFile CurrentDb.Name, objFSOFolder.Path & "\Backup No " &
Format(TheMax + 1, "0000") & " " & strThisApp & Mid(CurrentDb.Name,
InStrRev(CurrentDb.Name, "."))
RunCommand acCmdSave
End Sub

On Tue, Jun 16, 2015 at 9:53 AM, Bill Benson <bensonforums at gmail.com> wrote:

> I have been burned WAY too many times saving a database and then realizing
> something was not quite right, and not having a backup, screwed-ville.
>
> So, I wrote a routine to create a backup of the database in its original
> condition.
>
> What I want to add to this is a step to actually save the database without
> having to press Ctrl-S.
>
> The only thing I can find without resorting to SendKeys is the DoCmd.Save
> method, but this appears (to me) to apply to objects, rather than the full
> database? Am I right about that - and more to the point, is there a command
> to save the database?
>
> TIA
>


More information about the AccessD mailing list