Question : How do I create a new MS Access file when copying linked MSQL Tables to a local MS Access table?

I have a MS Access 2007 database linked to MS SQL tables. I currently can with Vb copy the mssql tables into a local MS Access table, for a backup. The problem is I have to create the local empty MS Access file and place it in the location the code refers to first. Also if I try to create a second copy I have to either rename the file or move it to a new location then create a new local empty Access file. So I need the abilty with vb code to create the local file and if a second back up is needed have it create a new file but with a new name so it does not overwrite the old file.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
Private Sub backup_Click()
Dim strSQL As String, strName As String
Dim RepDB As String
RepDB = "C:\Users\Sean\Desktop\backup.accdb"

strSQL = "SELECT tbladditionalsubject.* INTO tbladditionalsubject IN '" & RepDB & "'FROM tbladditionalsubject"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbladdlog.* INTO tbladdlog IN '" & RepDB & "'FROM tbladdlog"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbladdsubjectvehicle.* INTO tbladdsubjectvehicle IN '" & RepDB & "'FROM tbladdsubjectvehicle"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblappointments.* INTO tblappointments IN '" & RepDB & "'FROM tblappointments"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblattorney.* INTO tblattorney IN '" & RepDB & "'FROM tblattorney"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblclientnotes.* INTO tblclientnotes IN '" & RepDB & "'FROM tblclientnotes"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblclients.* INTO tblclients IN '" & RepDB & "'FROM tblclients"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbldetail.* INTO tbldetail IN '" & RepDB & "'FROM tbldetail"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbleimagepath.* INTO tbleimagepath IN '" & RepDB & "'FROM tbleimagepath"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblemployeenotes.* INTO tblemployeenotes IN '" & RepDB & "'FROM tblemployeenotes"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblemployees.* INTO tblemployees IN '" & RepDB & "'FROM tblemployees"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblexpensedetail.* INTO tblexpensedetail IN '" & RepDB & "'FROM tblexpensedetail"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblftp.* INTO tblftp IN '" & RepDB & "'FROM tblftp"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblgpsdevice.* INTO tblgpsdevice IN '" & RepDB & "'FROM tblgpsdevice"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblinsured.* INTO tblinsured IN '" & RepDB & "'FROM tblinsured"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblinvoicenotice.* INTO tblinvoicenotice IN '" & RepDB & "'FROM tblinvoicenotice"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblinvoicetable.* INTO tblinvoicetable IN '" & RepDB & "'FROM tblinvoicetable"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblletters.* INTO tblletters IN '" & RepDB & "'FROM tblletters"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbllog.* INTO tbllog IN '" & RepDB & "'FROM tbllog"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblpayment.* INTO tblpayment IN '" & RepDB & "'FROM tblpayment"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblprocess.* INTO tblprocess IN '" & RepDB & "'FROM tblprocess"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblprocessdetail.* INTO tblprocessdetail IN '" & RepDB & "'FROM tblprocessdetail"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblrates.* INTO tblrates IN '" & RepDB & "'FROM tblrates"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblsubjects.* INTO tblsubjects IN '" & RepDB & "'FROM tblsubjects"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblsubjectvehicle.* INTO tblsubjectvehicle IN '" & RepDB & "'FROM tblsubjectvehicle"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbltax.* INTO tbltax IN '" & RepDB & "'FROM tbltax"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbltaxrate.* INTO tbltaxrate IN '" & RepDB & "'FROM tbltaxrate"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbltimeline.* INTO tbltimeline IN '" & RepDB & "'FROM tbltimeline"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbltrackdetail.* INTO tbltrackdetail IN '" & RepDB & "'FROM tbltrackdetail"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbltrackgps.* INTO tbltrackgps IN '" & RepDB & "'FROM tbltrackgps"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tbltypecontact.* INTO tbltypecontact IN '" & RepDB & "'FROM tbltypecontact"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblupdatetable.* INTO tblupdatetable IN '" & RepDB & "'FROM tblupdatetable"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblusersettings.* INTO tblusersettings IN '" & RepDB & "'FROM tblusersettings"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblvendor.* INTO tblvendor IN '" & RepDB & "'FROM tblvendor"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblwebdoc.* INTO tblwebdoc IN '" & RepDB & "'FROM tblwebdoc"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblwebsettings.* INTO tblwebsettings IN '" & RepDB & "'FROM tblwebsettings"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblreport1.* INTO tblreport1 IN '" & RepDB & "'FROM tblreport1"
CurrentDb.Execute strSQL, dbFailOnError
strSQL = "SELECT tblreport2.* INTO tblreport2 IN '" & RepDB & "'FROM tblreport2"
CurrentDb.Execute strSQL, dbFailOnError
MsgBox "Completed"
End If
End If
End If
End If
End Sub

Answer : How do I create a new MS Access file when copying linked MSQL Tables to a local MS Access table?

You can just append the date/time to that database name:

RepDB = "C:\Users\Sean\Desktop\backup_" & Day(Now) & Month(Now) & Year(Now) & "_" & Hour(Now) & Minute(Now) & Second(Now) & ".accdb"

You may not need the Hour Minute Second part, but I included that anyway.
Random Solutions  
 
programming4us programming4us