Good morning everyone,
can anyone give me example of how to programatically copy an existing database to another location and rename the copied version - sort of a backup.

I have a database name "DbProd" which is located on a server, and I want to copy this database to either the same server or my hardrive "C:\". Also I would like to rename the database to "DBBackup" or any name of my choice.

Thanks.
tgifgemini.

Why not use FileCopy?

FileCopy(Source As String, Destination As String)

HI,
there are so many methods to implement file copy,
as SCBWV said,
you can use Filecopy to copy the DB

ToRename the File try the Follwing code

Name "c:\temp\test.mdb" As "c:\temp\test1.mdb"

hope this code will help you

With regards
Venkatramasamy SN

Thanks guys.
your input was quite understand and implemented successfully.
Happy new year to you all.
tgif.

hi , i want to copy my database file using VB 6 codes to another location. i used 'filecopy' command. But, an error "permission denied!" error is occuring. So, please help me to copy that database file in same propram....

hi , i want to copy my database file using VB 6 codes to another location. i used 'filecopy' command. But, an error "permission denied!" error is occuring. So, please help me to copy that database file in same propram....

Function Exists(Filename As String) As Boolean
Exists = (Dir(Filename) <> "")
End Function

Sub CreateDBBackup()
Dim St As String, Data As String

If Dir("Backup", vbDirectory) = vbNullString Then MkDir "Backup"
St = App.Path + "\Backup\DBBackup.dat"
Open "Database.dat" For Binary Access Read As #1
Open St For Binary Access Write As #2
Data = Space(LOF(1))
Get #1, , Data
Put #2, , Data
Close #2
Close #1
End If

End Sub

I request tgifgimini to mark your thread as resolved.

Good morning everyone,
can anyone give me example of how to programatically copy an existing database to another location and rename the copied version - sort of a backup.

I have a database name "DbProd" which is located on a server, and I want to copy this database to either the same server or my hardrive "C:\". Also I would like to rename the database to "DBBackup" or any name of my choice.

Thanks.
tgifgemini.

Public Sub Compact_DB()
    On Err GoTo DataError
   Dim Data As String
    'executed after closing databases
   ' 'The database is kept in the same folder as the program.
   ' 'Backup databases are in a backup folder       'E:\VB\VID_SS\COMMON\HELP

'TESTING:  Exit Sub
            
      Dim Oldname, Newname
    ' if dbhuntsman.
     
      With dbhuntsman
          .Close
      End With
      GoTo NoError
      
DataError:
        strError = Data
        Call Common_Error
        strReply = MsgBox("Error loading Golfer Excel File - " & Data, vbOKOnly)
        'GoTo GetNextRecord
NoError:
     dbHuntsman1.Close
     dbHuntsman2.Close
    'dbHuntsman3.Close
   
      'DBEngine.CompactDatabase strDefaultDB, "c:/huntsmanbackup/huntsmannew.mdb"
    If Dir(strBackupLocation & "/huntsmanbackup.mdb") <> "" Then
            Kill (strBackupLocation & "/huntsmanbackup.mdb")
        End If
        DBEngine.CompactDatabase strDefaultDB, strBackupLocation & "/huntsmanbackup.mdb"
        
      If Dir(strBackupLocation & "/huntsman3.mdb") <> "" Then
          Kill (strBackupLocation & "/huntsman3.mdb")
      End If
      If Dir(strBackupLocation & "/huntsman2.mdb") <> "" Then
            DBEngine.CompactDatabase strBackupLocation & "/huntsman2.mdb", strBackupLocation & "/huntsman3.mdb"
            'OldName = strBackupLocation & "/huntsman2.mdb": NewName = strBackupLocation & "/huntsman3.mdb"   ' Define file names.
          'Name OldName As NewName   ' Rename file.
      End If
    
      If Dir(strBackupLocation & "/huntsman2.mdb") <> "" Then
          Kill (strBackupLocation & "/huntsman2.mdb")
      End If
    
      If Dir(strBackupLocation & "/huntsman1.mdb") <> "" Then
             DBEngine.CompactDatabase strBackupLocation & "/huntsman1.mdb", strBackupLocation & "/huntsman2.mdb"
            'OldName = strBackupLocation & "/huntsman1.mdb": NewName = strBackupLocation & "/huntsman2.mdb"   ' Define file names.
          'Name OldName As NewName   ' Rename file.
      End If

If Dir(strBackupLocation & "/huntsman1.mdb") <> "" Then
          Kill (strBackupLocation & "/huntsman1.mdb")
      End If
    
      If Dir(strBackupLocation & "/huntsmanBackup.mdb") <> "" Then
          DBEngine.CompactDatabase strBackupLocation & "/huntsmanBackup.mdb", strBackupLocation & "/huntsman1.mdb"
      End If
    If Dir(strBackupLocation & "/huntsmannew.mdb") <> "" Then
        Kill (strBackupLocation & "/huntsmannew.mdb")
        Oldname = strBackupLocation & "/huntsmannew.mdb": Newname = strBackupLocation & "/huntsman.mdb"   ' Define file names.
        Name Oldname As Newname   ' Rename file.
    End If
    
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.