|
Access xp新增了FileDialog属性,方便了不少,可是在运行时状态下该属性会出错
比如新建一个可以指定备份路径的数据库备份窗体,对后台数据data_be.mdb进行备份,窗体包含一个TxtPath文本框、一个用于打开对话框的CmdSelectPtah按钮和一个进行备份操作Cmdbf按钮,如果该数据库一旦加入/runtime参数启动,在单击CmdSelectPtah按钮时就会提示出错,而常规启动则运行正常。代码如下:
-------------------------------------------------------------------------------------------------
Option Compare Database
Option Explicit
-------------------------------------------------------------------------------------------
Private Sub CmdSelectPtah_Click()'指定备份路径
Dim fd As FileDialog
Dim U As Variant
Set fd = Application.FileDialog(4)
If fd.Show = -1 Then
For Each U In fd.SelectedItems
If Right(U, 1) <> "\" Then
Me.TxtPath = U & "\"
Else
Me.TxtPath = U
End If
Next
End If
End Sub
----------------------------------------------------------------------------------------------------------------
Private Sub Cmdbf_Click()'备份操作
Dim P As String'声明备份路径变量
If IsNull(TxtPath) Then
MsgBox "没有指定存取路径", vbInformation + vbOKOnly, "提示"
Exit Sub
End If
If Right(CurrentProject.Path, 1) <> "/" Then
P = CurrentProject.Path & "/"
Else
P = CurrentProject.Path
End If
On Error GoTo ERR:
FileCopy P & "data_be.mdb", _
TxtPath & "DATA(" & Date & ").MDB"
DoCmd.Close
MsgBox "数据库备份完毕!" & Chr(13) & "文件名为ATA(" & Date & ").MDB", vbOKOnly, "提示"
exit_sub:
Exit Sub
ERR:
MsgBox "发生错误,可能指定的路径无效", vbInformation + vbOKOnly, "提示"
Exit Sub
End Sub
-----------------------------------------------------------------------------------------------------------------
|
|