VB 数据备份、还原

新建一个窗口,添加2个Command控件,1个Text控件,1个Drive控件,1个File,进行数据的备份和还原,代码如下:

Private Sub Command1_Click()
    msg = MsgBox("是否确定需要备份?", 1, "数据备份")
 Text1.Visible = True
 Drive1.Visible = True
  Text1.Text = "备份至"
End Sub

Private Sub Command2_Click()
    msg = MsgBox("数据还原会复盖电脑里面的数据,是否继续?", 4, "数据还原")
 Text1.Visible = True
 File1.Visible = True
 Drive1.Visible = True
  Text1.Text = "数据来自"
End Sub

Private Sub Drive1_Change()
 Dim s As String
      '备份数据库
If Text1.Text = "备份至" Then
      s = Drive1 & "/db1.mdb"
  On Error GoTo errprompt
  Me.MousePointer = 11
  FileCopy App.Path & "/db1.mdb", s
  Text1.Visible = False
  Drive1.Visible = False
  Me.MousePointer = 0
  MsgBox "数据已备份完毕!"
End If
 
If Text1.Text = "数据来自" Then
  File1.Path = Drive1.Drive         '改变驱动盘后文件跟着改变显示,这句非常重要。
     s = Drive1 & File1
        '还原数据库
  On Error GoTo errprompt
  Me.MousePointer = 11
FileCopy s, App.Path & "/db1.mdb"
 Text1.Visible = False
 Drive1.Visible = False
 File1.Visible = False
  Me.MousePointer = 0
  MsgBox "数据已还原完毕!"
End If

errprompt:
    Me.MousePointer = 0
  Select Case Err.Number
    Case 57
      MsgBox "磁盘已坏!", vbCritical
    Case 70
      MsgBox "磁盘写保护,重新开始!", vbCritical
      Unload Me
    Case 71
      MsgBox "磁盘未准备好!", vbCritical
  End Select

End Sub

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值