MS 访问运行时 - 文件对话框失败



我希望你能在这里帮助我... 我在 MS Access 2013 中有一个应用程序 (.accdb(。我在按钮单击时有一个文件对话框功能。(MSGBOX函数用于调试!

Private Sub Browse_btn_Click()
Dim path As String, initialPath As String
Dim fd As Object
MsgBox "Function Starts"
On Error GoTo errhnd
If IsNull(Me.RPE_Txt.value) Then initialPath = "C:users" & Environ("USERNAME") & "" _
Else: initialPath = Me.RPE_Txt.value
MsgBox "Setting FD"
Set fd = Application.FileDialog(3)

On Error GoTo errhnd
With fd
MsgBox "in fd with statement"
.Title = "RPE File"
MsgBox "fd.initialview"
.InitialView = 2
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel Files", "*.csv"
.InitialFileName = initialPath
MsgBox "show"
.Show
MsgBox "path"
path = .SelectedItems(1)
End With
MsgBox "end with"
Me.RPE_Txt.value = path
Exit Sub
errhnd:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
End Sub

当我在 MS 访问运行时 2010 上运行它时,当我单击按钮和访问崩溃时,我收到标准运行时错误...

我尝试使用以下代码添加引用,但它在尝试中崩溃了。

If Application.Version = 14# Then
MsgBox "Office 2010"
If Dir("C:Program FilesCommon Filesmicrosoft sharedOFFICE14MSO.DLL") <> "" And Not refExists("OFFICE") Then
MsgBox "Applying Reference for 2010 Office"
'Application.References.AddFromFile "C:Program FilesCommon Filesmicrosoft sharedOFFICE14MSO.dll"
Application.References.AddFromGuid "{398E906A-826B-48DD-9791-549C649CACE5}", 14#, 14#
MsgBox "Office 2010 Reference Applied!"
End If
ElseIf Application.Version = 15# Then
MsgBox "Office 2013"
If Dir("C:Program FilesCommon Filesmicrosoft sharedOFFICE15MSO.dll") <> "" And Not refExists("OFFICE") Then
MsgBox "Applying Reference for 2013 Office"
Application.References.AddFromFile "C:Program FilesCommon Filesmicrosoft sharedOFFICE15MSO.dll"
MsgBox "Office 2013 Reference Applied!"
End If
End If

任何帮助将不胜感激!

谢谢 皮特!

可悲的是,FileDialog在运行时不起作用。

可以在此处找到经常引用的替换代码:

API:调用标准 Windows 文件打开/保存对话框

它啰嗦,但它有效。

最新更新