Hello,
I am trying to do back-up macro for my database.
Every day automatically my access runtime database (Database1) runs in order to do macro (Function is for autoexec module to run automatically on database open)
	
	
	
		
Problem is within for each loop. My tables are found and command:
"DoCmd.CopyObject sFile, , acTable, oTD.Name" causes error:
"Access cant find object "tbl_Employee"".
I think that problem is connected with DoCmd because docmd is working within only current database (with macro).
I have tested it and if in my database1 there is a tbl_Employee - all is working fine. How to do DoCmd within another database?
How to solve the problem?
Best wishes,
Jacek Antek
 I am trying to do back-up macro for my database.
Every day automatically my access runtime database (Database1) runs in order to do macro (Function is for autoexec module to run automatically on database open)
		Code:
	
	
	Function DesignView()
    
    Dim sFile As String
    Dim oDB As dao.Database
    Dim oTD As TableDef
    Dim OtherDB As dao.Database
    Dim sPath As String
    
//Curent date for back up database
    sFile = CurrentProject.Path & "\Archiwum" & "\" & Format(Date, "DD-MM-YYYY") & ".accdb"
//creating new database
    On Error Resume Next
    Set oDB = DBEngine.Workspaces(0).CreateDatabase(sFile,  
    dbLangGeneral)
    oDB.Close
//try to loop through another database abd copy all tables into created database in sFile
    Set OtherDB = OpenDatabase("C:\Users\ljar01\Desktop\Makro\Makro IBS\Raport Błędów\Aplikacja_Błędy_BE.accdb")
    DoCmd.Hourglass True
    
[B]For Each oTD In OtherDB.TableDefs
       If Left(oTD.Name, 4) <> "MSys" Then
            DoCmd.CopyObject sFile, , acTable, oTD.Name
       End If
Next oTD[/B]
    OtherDB.Close
    DoCmd.Hourglass False
    
    MsgBox "Done!"
    
End Function
	Problem is within for each loop. My tables are found and command:
"DoCmd.CopyObject sFile, , acTable, oTD.Name" causes error:
"Access cant find object "tbl_Employee"".
I think that problem is connected with DoCmd because docmd is working within only current database (with macro).
I have tested it and if in my database1 there is a tbl_Employee - all is working fine. How to do DoCmd within another database?
How to solve the problem?
Best wishes,
Jacek Antek