Private Sub Command1_Click()
Dim retvaL
Dim abc
Dim lxx
lxx = Dir1.Path + "\备份.mdb"
retvaL = copyfile("D:\download\毕业设计\易耗易损件材料管理系统\易耗易损件.MDB", lxx, 1)
MsgBox "备份结束"
Unload Me
 End Sub
是用来复制文件的
但这个文件有个BUG就是如果目标文件已经存在,他就不能复制过去进行复盖,有谁有办法帮我解决啊

解决方案 »

  1.   

    Dim fs_send As Object
    Set fs_send = CreateObject("Scripting.FileSystemObject")
    '测试指定路径的文件是否已存在
    if fs_send.fileexists(Dir1.Path + "\备份.mdb") then
        if MsgBox("目标文件已经存在,是否覆盖?", vbYesNo, "提示")=vbyes then
            '删除文件
            Kill Dir1.Path + "\备份.mdb"
        Else
            Exit Sub   '退出
        End If
    End If'另外,申明变量时最好能指定数据类型