Delete / Rename database

RevJeff

Registered User.
Local time
Today, 13:31
Joined
Sep 18, 2002
Messages
129
Hi Everyone,

I am creating an update database (DB A) that when opened it will copy various tables, queries & reports from DB B and put them in DB C. Then I want to delete DB B and rename DB C to what DB B was named. I am able to copy the table, queries & reports over, but not sure how to delete DB B and rename DB C from within DB A.

Thanks,
Jeff
 
You could use some of the code further below to rename the database. My db has information in a table regarding dates, so if yours doesn't you would need to modify this code accordingly. For deleting a file you can use this

Kill path & filename
or you could use fso.DeleteFile, but would need to check syntax on file name.

Code:
Private Sub cmdBackup_Click()
    'Backup last week's file.
    'Give file name of most recent rundate based on the date in the chart table.
    'Check if File Exists. If file has already been backed up, don't do again
    '08-JUL-2010
    
    Dim fso As New FileSystemObject
    Dim stTerm As String
    Dim stSourceFile As String
    Dim stPath As String
    Dim stBackupName As String

    
    stSourceFile = CurrentDb.Name
    stPath = "c:\accessfiles\"
    stBackupName = Replace(Dir$(CurrentDb.Name), ".mdb", "_" & Format(DMax("rundate", "tblChart_UG"), "YYYYMMDD")) & ".mdb"
    
    stTerm = Mid(Me.txtCurrentTerm, 3, 2)
    
    If Dir(stPath & stBackupName) = "" Then
        
        fso.CopyFile stSourceFile, stPath & stBackupName '"\\someOtherComputer\share\foo.mdb", "C:\foo.mdb"
        
        MsgBox "The following Files have been backed up:" & vbCrLf & _
                stPath & stBackupName & vbCrLf & _
                , vbOKOnly
    Else
        MsgBox "The following Files have already been backed up:" & vbCrLf & _
                stPath & stBackupName & vbCrLf & _
                , vbOKOnly
    End If
    
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom