请帮我看看这段代码,谢谢
我是一个新手,刚看vb没几天,从网上看到一个备份access数据的实例,但是照写下来编译却通不过,请大家帮我看看,不要笑我菜,谢谢
Option Explicit
Dim dbasize As Long
Dim dbasize2 As Long
Dim PathName As String
Dim NoDba As Boolean
Private mclsMidTier As clsMidTier
Dim DB As Connection
Private Sub cmdClose_Click()
frmDatabaseRestore.Hide
Unload frmDatabaseRestore
End Sub
Private Sub cmdRestore_Click()
If MsgBox( "恢复数据库从 " & txtSource & " 将替换已经存在的文件。你想继续吗? ", vbYesNo) = vbYes Then
DoRestore txtSource.Text, App.Path
' If NoDba = True Then
MsgBox "恢复数据库成功,单击[确定]然后退出程序! "
frmDatabaseRestore.Hide
Unload frmDatabaseRestore
' End If
Else
lblStatus.Caption = "恢复数据库被中止! "
End If
End Sub
Private Sub cmdSource_Click()
On Error GoTo Erro
Dim strTemp As String
strTemp = fBrowseForFolder(Me.hWnd, "Restore From ")
If strTemp <> " " Then
txtSource = strTemp
dbasize2 = FileLen(txtSource & "\Student.MDB ")
lblSelectedDba = "请选择所备份的数据库文件 : " & Format((dbasize2 / 1024) / 1024, "standard ") & "MB. "
cmdRestore.Enabled = True
End If
Erro:
Select Case err.Number
Case 53 'File Not Found
lblSelectedDba = "没有选择备份文件位置! "
cmdRestore.Enabled = False
End Select
End Sub
Private Sub Form_Activate()
lblSize = Format((dbasize / 1024) / 1024, "standard ") & "MB. "
End Sub
Private Sub Form_Load()
PathName = App.Path & "\Student.MDB "
On Error GoTo err
dbasize = FileLen(PathName)
err:
Exit Sub
End Sub
Public Sub DoRestore(strSourcePath As String, strDestinationPath As String)
On Error Resume Next
Dim lFileOp As Long
Dim lresult As Long
Dim lFlags As Long
Dim SHFileOp As SHFILEOPSTRUCT
Dim strSourceDir As String
Dim strDestinationDir As String
Screen.MousePointer = vbHourglass
BackupFolderName = strDestinationPath
lFileOp = FO_COPY
lFlags = lFlags And Not FOF_SILENT
lFlags = lFlags Or FOF_NOCONFIRMATION
lFlags = lFlags Or FOF_NOCONFIRMMKDIR
lFlags = lFlags Or FOF_FILESONLY
With SHFileOp
.wFunc = lFileOp
.pFrom = strSourcePath & "\Student.MDB " & vbNullChar
.pTo = strDestinationPath & vbNullChar
.fFlags = lFlags
End With
lresult = SHFileOperation(SHFileOp)
' Set DB = New ADODB.Connection
' DB.Open mclsMidTier.strConnString()
Screen.MousePointer = vbDefault
frmDatabaseRestore.lblStatus = "恢复数据库成功! "
End Sub
[解决办法]
clsMidTier应该是自定义的一个类。