希望您能在这里帮助我...
我在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 Access Runtime 2010上运行此命令时,单击按钮,Access崩溃...时,我收到标准的Runtime Error。
我尝试使用下面的代码添加引用,但尝试失败。
If Application.Version = 14# Then
MsgBox "Office 2010"
If Dir("C:\Program Files\Common Files\microsoft shared\OFFICE14\MSO.DLL") <> "" And Not refExists("OFFICE") Then
MsgBox "Applying Reference for 2010 Office"
'Application.References.AddFromFile "C:\Program Files\Common Files\microsoft shared\OFFICE14\MSO.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 Files\Common Files\microsoft shared\OFFICE15\MSO.dll") <> "" And Not refExists("OFFICE") Then
MsgBox "Applying Reference for 2013 Office"
Application.References.AddFromFile "C:\Program Files\Common Files\microsoft shared\OFFICE15\MSO.dll"
MsgBox "Office 2013 Reference Applied!"
End If
End If
任何帮助将不胜感激!
谢谢, 皮特!
答案 0 :(得分:2)
不幸的是,FileDialog在运行时无法运行。
可以在这里找到经常提及的替换代码:
API: Call the standard Windows File Open/Save dialog box
大风吹拂,但有效。