Hey,
Basically the code below, should first create a database and then copy the tables from one database to another. At the moment I am using another access database file to perform this task, (I would code it in VB, but we don't currently own a version). This code works a treat if you copy the CurrentDB where the code is running to a new database, but I need the code to access another database, the code I have used is below. As you can see I have replaced the CurrentDB with the necessary path name. The error I get though is...
The Microsoft Jet database engine could not find the object 'TableNameInHere'. Make sure the object exists and that you spell its name and the path name correctly.
I understand the problem but as it works using currentDB i'm stuck Any help is greatly appreciated,
Cheers
Sam
Code Is here
Sub sExport(strDBName As String)
On Error GoTo E_Handle
Dim db As DAO.Database
Dim tdf As DAO.TableDef
If Dir(strDBName) <> "" Then Kill strDBName
Set db = DBEngine(0).CreateDatabase(strDBName, dbLangGeneral)
db.Close
Set db = DBEngine.OpenDatabase("C:\Documents and Settings\SSh\Desktop\Copy of Crack2.mdb"
'Set db = CurrentDb
For Each tdf In db.TableDefs
If Left(tdf.Name, 4) <> "MSys" Then
DoCmd.TransferDatabase acExport, "Microsoft Access", strDBName, acTable, tdf.Name, tdf.Name
End If
Next tdf
MsgBox "Tables copied OK", vbOKOnly, " "
sExit:
Set db = Nothing
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly, Err.Number
Resume sExit
End Sub
"You couldn't fool your mother on the foolingest day of your life if you had an electrified fooling machine." - Homer
Basically the code below, should first create a database and then copy the tables from one database to another. At the moment I am using another access database file to perform this task, (I would code it in VB, but we don't currently own a version). This code works a treat if you copy the CurrentDB where the code is running to a new database, but I need the code to access another database, the code I have used is below. As you can see I have replaced the CurrentDB with the necessary path name. The error I get though is...
The Microsoft Jet database engine could not find the object 'TableNameInHere'. Make sure the object exists and that you spell its name and the path name correctly.
I understand the problem but as it works using currentDB i'm stuck Any help is greatly appreciated,
Cheers
Sam
Code Is here
Sub sExport(strDBName As String)
On Error GoTo E_Handle
Dim db As DAO.Database
Dim tdf As DAO.TableDef
If Dir(strDBName) <> "" Then Kill strDBName
Set db = DBEngine(0).CreateDatabase(strDBName, dbLangGeneral)
db.Close
Set db = DBEngine.OpenDatabase("C:\Documents and Settings\SSh\Desktop\Copy of Crack2.mdb"
'Set db = CurrentDb
For Each tdf In db.TableDefs
If Left(tdf.Name, 4) <> "MSys" Then
DoCmd.TransferDatabase acExport, "Microsoft Access", strDBName, acTable, tdf.Name, tdf.Name
End If
Next tdf
MsgBox "Tables copied OK", vbOKOnly, " "
sExit:
Set db = Nothing
Exit Sub
E_Handle:
MsgBox Err.Description, vbOKOnly, Err.Number
Resume sExit
End Sub
"You couldn't fool your mother on the foolingest day of your life if you had an electrified fooling machine." - Homer