I hope you can help me out here...
I have a application in MS Access 2013 (.accdb
). I have a file dialog function on the button click. (MSGBOX
Functions are for debuging!)
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
When I run this on MS Access Runtime 2010 I am getting standard RunTime Error when I click the button and Access crashes...
I tried adding references with below code but it was crashing in the attempt..
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
Any help would be appreciated!
Thanks, Pete !
Sadly, the FileDialog doesn't work in the runtime.
An often referred replacement code can be found here:
API: Call the standard Windows File Open/Save dialog box
It's longwinded but it works.