I am trying to make a copy of an existing database from within a VB6 program.
I can create a new database with the appropriate name but when it comes to importing tables it falls over and an empty database only is created. All of my reading within
the books I have doesn't point me in any direction.The following code is what creates the db but not the tables and definitions, it comes from online help examples with VB6:D.
Anybody held.
Regards peterf
Public Function CreateDB()
Dim newdb As Database, mydb As Database
Dim dbname As String
Dim tdf As TableDef
Dim DateSave, TimeSave
Dim newdb1
Dim StoreFolder
DateSave = Format(Date, "ddmmyy")
TimeSave = Format(Time, "hhmm")
newdb1 = TimeSave & " " & DateSave & " Database.mdb"
StoreFolder = "C:\Database\Backup\"
'Set the path and name for the new database.
dbname = StoreFolder & newdb1
'Create the new database and close newdb.
Set newdb = DBEngine.Workspaces(0).CreateDatabase(dbname, _
dbLangGeneral)
newdb.Close
'Export all non-system tables to the database.
Set mydb = CurrentDb()
For Each tdf In mydb.TableDefs
If (tdf.Attributes And dbSystemObject) = 0 Then
DoCmd.TransferDatabase acExport, "Microsoft Access", _
dbname, acTable, tdf.Name, tdf.Name
End If
Next tdf
End Function