Office中国论坛/Access中国论坛

标题: 前台中备份后台数据库例子 [打印本页]

作者: 咱家是猫    时间: 2011-7-19 23:37
标题: 前台中备份后台数据库例子
我是把它们放在"我的文档"文件夹的
  1. Option Compare Database

  2. Function SysSet(SetName As String)
  3. '提取系统设置的函数

  4. On Error GoTo Err_SysSet

  5. SysSet = DLookup("[" & SetName & "]", "备份设置")

  6. Exit_SysSet:
  7. Exit Function

  8. Err_SysSet:

  9. MsgBox Err.Description
  10. Resume Exit_SysSet

  11. End Function

  12. Sub DefaultBackUp()

  13. Dim WinRARPath As String
  14. Dim BackFile As String
  15. Dim BackPath As String
  16. Dim BackUpFile As String
  17. Dim StrCMD As String

  18. If Not IsNull(SysSet("WinRAR路径")) Then
  19. WinRARPath = SysSet("WinRAR路径")
  20. Else
  21. Do
  22. WinRARPath = ShowFolderDlg("确认 WinRAR 程序安装的文件夹。")

  23. If WinRARPath = "" Then
  24. MsgBox "备份任务取消!" & Chr(13) & Chr(10) & Chr(10) & "未确认 WinRAR.exe 程序的安装路径,系统需要此程序来完成备份任务。", vbInformation, "North Star"
  25. Exit Sub
  26. End If
  27. If Dir(WinRARPath + "\WinRAR.exe") = "" Then
  28. MsgBox "指定文件夹中未找到 WinRAR.exe 程序!" & Chr(13) & Chr(10) & Chr(10) & "请重新选择。", vbExclamation, "North Star"
  29. End If
  30. Loop While Dir(WinRARPath + "\WinRAR.exe") = ""
  31. End If
  32. If Not IsNull(SysSet("备份路径")) Then
  33. BackUpPath = SysSet("备份路径")
  34. Else
  35. BackUpPath = ShowFolderDlg("选择一个存放备份数据文件的文件夹。" & Chr(13) & Chr(10) & Chr(13) & "请设置为不同与后台数据路径的另一驱动器路径。")
  36. If BackUpPath = "" Then
  37. MsgBox "备份任务取消!" & Chr(13) & Chr(10) & Chr(10) & "您未指定存放备份数据文件的文件夹。", vbInformation, "North Star"
  38. Exit Sub
  39. End If
  40. End If
  41. BackFile = DLookup("[Database]", "MSysObjects", "Database<>Null")
  42. BackUpFile = BackUpPath & "\BK" & Format(Date, "yyyymmdd")
  43. StrCMD = """" & WinRARPath & "\WinRAR.exe"" a -ep -p123456 """ & BackUpFile & """ """ & BackFile & """"

  44. '压缩备份后台数据库
  45. Shell StrCMD, vbNormalFocus

  46. End Sub

  47. Function ShowFolderDlg(strDialogTitle As String) As String
  48. '函数作用:使用SHELL对象显示浏览文件夹对话框,返回文件夹路径,这是目前最简单的方式,不需要API函数.
  49. '函数参考:代码来自OFFICE精英俱乐部
  50. '函数范例:me.text1=ShowFolderDlg("请选择一个数据库文件......")
  51. '测试状态:OK

  52. Dim shApp As Object, Path1 As Object
  53. Set shApp = CreateObject("Shell.application")
  54. Set Path1 = shApp.BrowseForFolder(0, strDialogTitle, 0, 17)
  55. If Path1 Is Nothing Then Exit Function
  56. ShowFolderDlg = IIf(IsError(Path1.items.Item.Path), Path1.Title, Path1.items.Item.Path)

  57. End Function
复制代码
[attach]57407[/attach]
[attach]57406[/attach]

[attach]46139[/attach]


作者: nienie2010    时间: 2011-7-20 15:56
多谢分享
作者: wuheng    时间: 2011-7-20 16:17
谢谢分享,下了学习~~~~~~~~
作者: wuheng    时间: 2011-7-20 16:18
谢谢分享,下了学习~~~~~~~~
作者: 82077802    时间: 2011-7-20 19:46
谢谢分享,下了学习~~~~~~~~

作者: stwuyiyu    时间: 2011-7-20 21:10
谢谢啊,学习了
作者: asklove    时间: 2011-7-21 08:47
收藏,备用,谢谢!
作者: ZenJing    时间: 2012-8-20 16:47
谢谢,下了学习
作者: daviee    时间: 2013-11-6 16:46
弱弱地问一句,在那修改要备份的数据库路径,我的数据不是存放在“我的文档”中。谢谢!
作者: daviee    时间: 2013-11-8 11:10
楼主,用你的这个程序运行正常,导入到我的程序中运行,出现 “此窗体或报表上指定的记录源 RegisterInfo 不存在”,在你程序里怎么也没找到你的这个RegisterInfo源呀?!
作者: ljp518    时间: 2013-11-8 11:20
谢谢分享!
作者: fjh    时间: 2015-11-4 16:02
感谢分享




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3