473,508 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Backup Backend Database at the Back end Location

46 New Member
Hi I have a split database and a code to backup the back end at the front end however I want the back end to backed up in a folder called "Backups" a the Back End and not at the front end. This is the code am using now to back up the destination at the front end. Please help me change the destination to the back end(Server)

Expand|Select|Wrap|Line Numbers
  1. Public Sub BackUpDatabase()
  2.  
  3. On Error GoTo Err_Handler
  4.     Dim oFSO As Object
  5.     Dim strDestination As String
  6.     Dim strSource As String
  7.     Dim path As String, name As String
  8.  
  9.     path = CurrentProject.path
  10.     name = CurrentProject.name
  11.     Const conPATH_FILE_ACCESS_ERROR = 75
  12.  
  13.  'Get the source of the back end
  14.     strSource = Split(Split(CurrentDb.TableDefs("AssessmentT").Connect, "Database=")(1), ";")(0)
  15.  
  16.     'Determine backup destination
  17.     strDestination = path & "\" & Left(name, Len(name) - 6) & "_backup" & "_" & _
  18. Year(Now) & "_" & Month(Now) & "_" & Day(Now) & ".accdb"
  19.  
  20. 'this removes a file created on the same day
  21.     If Dir(strDestination) <> "" Then
  22.     Kill strDestination
  23.     End If
  24.  
  25. 'this creates a backup into destination path
  26.     If Dir(strDestination) = "" Then
  27.     'Flush the cache of the current database
  28.     DBEngine.Idle
  29.  
  30.     'Create a file scripting object that will backup the db
  31.     Set oFSO = CreateObject("Scripting.FileSystemObject")
  32.     oFSO.CopyFile strSource, strDestination
  33.     Set oFSO = Nothing
  34.  
  35.     'Compact the new file, ...
  36.     Name strDestination As strDestination & ".cpk"
  37.     DBEngine.CompactDatabase strDestination & ".cpk", strDestination
  38.     Kill strDestination & ".cpk"
  39.  
  40.     'Notify users
  41.     MsgBox "Backup file '" & strDestination & "' has been created.", vbInformation, "Backup Completed!"
  42.  
  43. End If
  44.  
  45. Exit_Button_Backup:
  46.  
  47.   Exit Sub
  48.  
  49. Err_Handler:
  50.   If Err.Number = conPATH_FILE_ACCESS_ERROR Then
  51.     MsgBox "The following Path, " & strDestination & ", already exists or there was an Error " & _
  52.            "accessing it!", vbExclamation, "Path/File Access Error"
  53.   Else
  54.     MsgBox Err.Description, vbExclamation, "Error Creating " & strDestination
  55.  
  56. End If
  57.     Resume Exit_Button_Backup
  58.  
  59.  
  60.  
  61. End Sub
  62.  
Dec 10 '13 #1
9 8414
zmbd
5,501 Recognized Expert Moderator Expert
Line #17: Alter this to change the path to the location desired...

Line#17 is based on the "name" and "path" in lines #9 and #10
Line #9 would more than likely be the easiest place to put your network or other drive/path information

You can also use: Select a File or Folder using the FileDialog Object use the "folder" method to have the user select the location returning the value to line #9

One other thing I noted in your code is the use of reserved tokens as variables ("name" "path" etc...). I highly advise against doing this as it will eventually cause you a nightmare of troubleshooting; thus, you might want to review::
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access
Dec 10 '13 #2
yashuaking
46 New Member
Thanks Zmbd I get your point about changing the path to the network location. I tried this and it worked but I realize whenever I have to install the program on another computer, I have to change the code to suite that network path but I do not want it this way. I want the database to detect the source path and create the backup in the folder on the source path.I want the backup to be saved in the Back end folder irrespective of which machine I install on it on. I also appreciate your view about the reserved words. I would work on that. Thanks for the quick answer.
Dec 10 '13 #3
yashuaking
46 New Member
This was the code I was using initially and it works fine but whenever I have to install on another computer, I have to go into the code and change the code to suite the new network path so I modified it into the above code which is also limiting me to the front end
Expand|Select|Wrap|Line Numbers
  1. Public Function Button_Backup()
  2. Dim str As String
  3. Dim buf As String
  4. Dim MD_Date As Variant
  5. Dim fs As Object
  6. Dim source As String
  7.  
  8. Const conPATH_FILE_ACCESS_ERROR = 75
  9. On Error GoTo Backup_Button_Backup
  10.  
  11. 'Where to backup to. Creates BACKUP folder is it does not exist
  12. If MsgBox("Do You want to backup database?", vbYesNo + vbQuestion, "Falcon Systems") <> vbYes Then Exit Function
  13. buf = path & "\\CREDIT-MANAGER\Falcon Systems\Data\Backups\"
  14. MkDir buf
  15.  
  16.     Resume Backup_Button_Backup
  17.  
  18. Backup_Button_Backup:
  19.  
  20. 'Create a folder in BACKUP with YYYY-mm-dd hhmm-ss as the name
  21.  
  22. MD_Date = Format(Date, "yyyy-mm-dd ") & Format(Time, "hh-mm-ss")
  23. str = path & "\\CREDIT-MANAGER\Falcon Systems\Data\Backups\" & MD_Date
  24.  
  25. 'Where is the data to backup
  26. source = path & "\\Credit-Manager\Falcon Systems\Data\"
  27. MkDir str
  28. Set fs = CreateObject("Scripting.FileSystemObject")
  29. fs.CopyFile source & "*.accde", str
  30. Set fs = Nothing
  31.  
  32. 'Successful
  33. MsgBox "A database backup has been stored by name" & vbCrLf & MD_Date & vbCrLf & "Successfully!", _
  34.         vbInformation, "Falcon Systems Backup Successful"
  35.  
  36. Exit_Button_Backup:
  37.  
  38.   Exit Function
  39.  
  40. 'Use this part if you have not used hh-mm-ss
  41.  
  42. Err_Button_Backup:
  43.   If Err.Number = conPATH_FILE_ACCESS_ERROR Then
  44.     MsgBox "The following Path, " & str & ", already exists or there was an Error " & _
  45.            "accessing it!", vbExclamation, "Path/File Access Error"
  46.   Else
  47.     MsgBox Err.Description, vbExclamation, "Error Creating " & str
  48.  
  49. End If
  50.     Resume Exit_Button_Backup
  51. End Function
  52.  
Dec 10 '13 #4
zmbd
5,501 Recognized Expert Moderator Expert
use the UNC naming convention.

For example:
My IT guys are very kind and my personal network drive is mapped to "Z:" however the UNC path is:
"\\servername\users\dept\qaqc\z_personaldrive\ "

(I also updated my first post :) )
Dec 10 '13 #5
yashuaking
46 New Member
Ok I'll try it. Thanks very much
Dec 10 '13 #6
yashuaking
46 New Member
But is there a way to use a path similar to this one:
Expand|Select|Wrap|Line Numbers
  1. strSource = Split(Split(CurrentDb.TableDefs("AssessmentT").Connect, "Database=")(1), ";")(0)
I tried using it as the destination but I received an error. Am thinking I have to modify this code to fall into the split folder instead of file
Dec 10 '13 #7
redneckfiveo
1 New Member
yashuaking ~ I know this is an older post, however for folks searching for an answer to your question I have two bits of code that may help.

I use a simple module to get the database backend path. The first one provides the exact directory where the backend resides.
Expand|Select|Wrap|Line Numbers
  1. Public Function GetDBBEPath() As String
  2. On Error GoTo GetDBBEPath_Err
  3.      Dim strFullPath As String
  4.      strFullPath = Mid(DBEngine.Workspaces(0).Databases(0).TableDefs("NameLinkedTable").Connect, 11)
  5.      GetDBBEPath = Left(strFullPath, InStrRev(strFullPath, "\"))
  6.      'for troubleshooting Debug.Print GetDBBEPath
  7. GetDBBEPath_Exit:
  8.     Exit Function
  9. GetDBBEPath_Err:
  10.     MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
  11.     VBE.ActiveCodePane.CodeModule & "(GetDBBEPath Function).", vbOKOnly, "Error"
  12.     LogError ("GetDBBEPath Error " & VBE.ActiveCodePane.CodeModule & " " & Err.Number & " " & Err.Description & " " & Err.Source & " " & CreateObject("WScript.Network").userName & " " & CreateObject("WScript.Network").ComputerName)
  13. End Function
  14. [/CODE}
  15. Please make sure you replace "NameLinkedTable" with any one of your linked table names.  The process is simple, if your linked tables are stored at I:\Databases\MyDatabase\Db.accbe, then the function returns ... I:\Databases\MyDatabase
  16. .
  17.  
  18. For ease, I have included another function which does the same, however steps up one subfolder.  I use this function a lot and have the need to access other folders in the same parent directory.  Please make sure you replace "NameLinkedTable" with one of your linked table names.
  19.  
  20. For this to work you also need to replace "\FolderName\" with whatever folder your BE file resides.  In the above sample, the \FolderName\ would read "\MyDatabase\"
  21.  
  22. [CODE}
  23. Public Function GetDBBEPathSub() As String
  24. On Error GoTo GetDBBEPathSub_Err
  25.  
  26. Dim strFullPath As String
  27.     strFullPath = Mid(DBEngine.Workspaces(0).Databases(0).TableDefs("NameLinkedTable").Connect, 11)
  28.     GetDBBEPathSub = Left(strFullPath, InStrRev(strFullPath, "\FolderName\"))
  29.      'Debug.Print GetDBBEPathSub
  30. GetDBBEPathSub_Exit:
  31.     Exit Function
  32. GetDBBEPathSub_Err:
  33.     MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
  34.     VBE.ActiveCodePane.CodeModule & "(GetDBBEPathSub Function).", vbOKOnly, "Error"
  35.     LogError ("GetDBBEPathSub Error " & VBE.ActiveCodePane.CodeModule & " " & Err.Number & " " & Err.Description & " " & Err.Source & " " & CreateObject("WScript.Network").userName & " " & CreateObject("WScript.Network").ComputerName)
  36. End Function
  37.  
When you need to use the folder path, simply call the function and add whatever you need afterwards such as this:
Expand|Select|Wrap|Line Numbers
  1. strDatabasePath = GetDBBEPath & "\" & "Folder or file path here" 
  2.  
Also, I didn't remove my crazy Error Handling or error logger. Happy coding!
Dec 15 '14 #8
neelsfer
547 Contributor
I use this utility i got from the net once upon a time. Customize it for you and check the code. It is a separate utility, but works great. Hold in shift when opening
Attached Files
File Type: zip BackUpUtility2007.zip (42.6 KB, 436 views)
Dec 15 '14 #9
twinnyfo
3,653 Recognized Expert Moderator Specialist
The .Connect call should be all that is needed. Then, once you have that string, removing the left 10 characters (";DATABASE=") will get you the entire path and file name. Then, from the end of the file name, look for the first "\" and take the Left() of the remaining string. I do this in a bit of an opposite way to find out the name of the DB to which my DB is linked. But once you have that string, it is merely an issue of manipulating or identifying the characters that you want/don't want.
Dec 16 '14 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1800
by: cloverme | last post by:
The database is configured for single publisher, many subscribers, merge replication. The maintenance plan started to fail a couple of months ago and the database would not get backed up. After...
11
1874
by: kusanagihk | last post by:
To all, How to backup a database into a number of smaller files ? For example, can I can fully backup a DB of 10 MB into 10 files (each 1 MB)??? The problem I've met is that the DB backup...
11
4487
by: HB2 | last post by:
I am using the Linked Table Manager in Access to try and connect my front end database (on my desktop) to my backend database (on my web host) I get an invalid name error. Any help much...
4
1855
by: Wayne | last post by:
I have a backend database (Backend1.mdb)that has 3 main data tables, I'll call them Data1, Data2 and Data3, plus several other associated tables. All relationships are set in the backend database...
7
13075
by: s w dunn | last post by:
Hello, I am in charge of maintaining a little ACCESS database used by our purchasing department. I need to add some new values to a table, but I can't open the .be database in order to access the...
0
1572
by: Scott | last post by:
I need to compact the backend database on server regularly using Jetcomp utility. Can this utility support commandline so I can do it with Windows scheduler. Your advice on the syntax is...
2
1161
by: zafar | last post by:
I need to creating backup of database on user defined location in hard disk. thanx for helping in this regard
0
1192
by: vishnutd4u | last post by:
Hi Friends, I am New To this forums.I have Some Doubt regarding taking backup in mysql on linux using VC++ code.By using Mysqldump i am taking backup of database but how to ask that code to...
0
1118
by: vishnutd4u | last post by:
Hi Friends, I am New To this forums.I have Some Doubt regarding taking backup in mysql on linux using VC++ code.By using Mysqldump i am taking backup of database but how to ask that code to perform...
0
1390
by: michael ngong | last post by:
pramod@rtimes.com (Pramod Ramachandran) wrote in message news:<6616e304.0306240122.4dd3ecd5@posting.google.com>... Permit me start with the second question. It would be easier to be more...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.