I need to move data in a table to tables in new databases for archiving; & being able to click a button & have the data append & delete is my goal.
I made a test database to work on the code. I'm an Access beginner & so go easy:
This code creates the archive & runs ArchiveTables (below) when I click a button. The code works fine when I don't use the variable name (strDBName) & instead just point to specific locations but I need the names to be generated as of the date. It's for my boss & to him it's important that that's how it works (so he can just push a button & have it archive in to a new file depending on the date).
Private Sub Archive_Click()
Dim dbnew As DAO.Database
Dim strDBName As String
Dim ArchiveDB As String
strDBName = Format(Date, "mmm d yyyy") & " Archive"
ArchiveDB = "G:\" & strDBName
Set dbnew = DBEngine(0).CreateDatabase("G:\" & strDBName, dbLangGeneral)
ArchiveTables (ArchiveDB)
dbnew.Close
Set dbnew = Nothing
End Sub
This is the TransferDatabase code (I want it to delete, too, but don't know how & want to get the transfer to work first):
Private Sub ArchiveTables(ArcDB As String)
Dim strDBName As String
strDBName = Format(Date, "mmm d yyyy") & " Archive"
DoCmd.TransferDatabase acExport, "Microsoft Access", "G:\" & strDBName, acTable, "tbl_testTable", "tbl_testTable", 0
End Sub
When I run this with the strDBName it gives me a
Run Time Error '3024':
Could not find file 'G:\Nov 5 2013 Archive'.
Even though the file was created & I can see it on the server; but no data was transferred to it.
I'm at a loss, & as I said, new to Access & wanting to get better.
If anybody has any advice with my problem, I would sincerely appreciate it.
I made a test database to work on the code. I'm an Access beginner & so go easy:
This code creates the archive & runs ArchiveTables (below) when I click a button. The code works fine when I don't use the variable name (strDBName) & instead just point to specific locations but I need the names to be generated as of the date. It's for my boss & to him it's important that that's how it works (so he can just push a button & have it archive in to a new file depending on the date).
Private Sub Archive_Click()
Dim dbnew As DAO.Database
Dim strDBName As String
Dim ArchiveDB As String
strDBName = Format(Date, "mmm d yyyy") & " Archive"
ArchiveDB = "G:\" & strDBName
Set dbnew = DBEngine(0).CreateDatabase("G:\" & strDBName, dbLangGeneral)
ArchiveTables (ArchiveDB)
dbnew.Close
Set dbnew = Nothing
End Sub
This is the TransferDatabase code (I want it to delete, too, but don't know how & want to get the transfer to work first):
Private Sub ArchiveTables(ArcDB As String)
Dim strDBName As String
strDBName = Format(Date, "mmm d yyyy") & " Archive"
DoCmd.TransferDatabase acExport, "Microsoft Access", "G:\" & strDBName, acTable, "tbl_testTable", "tbl_testTable", 0
End Sub
When I run this with the strDBName it gives me a
Run Time Error '3024':
Could not find file 'G:\Nov 5 2013 Archive'.
Even though the file was created & I can see it on the server; but no data was transferred to it.
I'm at a loss, & as I said, new to Access & wanting to get better.
If anybody has any advice with my problem, I would sincerely appreciate it.