josephwalter
Programmer
A button on one of my forms is supposed to open the File Open dialog box. It works fine on user's computer when I have Access installed (as part of Office XP Professional), but it doesn't work with just Access Runtime. User gets the error "Method 'FileDialog' of Object '_Application' failed."
Company policy will not allow me to keep a full version of Access on user's computer. What do I need to install in order to make my dialog box work? Below is the code I'm using:
Company policy will not allow me to keep a full version of Access on user's computer. What do I need to install in order to make my dialog box work? Below is the code I'm using:
Code:
Const USER_CLICKED_BUTTON As Integer = -1
Private Sub btnBrowse_Click()
On Error GoTo Proc_Error
' These procedures references the Microsoft Office 10.0 Object Library.
Dim objFileDialog As FileDialog
Dim strFilePath As String
strFilePath = "J:\path\to\company\files"
Set objFileDialog = BuildCommonDialogBox(msoDialogType:=msoFileDialogOpen, _
strTitleCaption:="Select a File", _
strFileName:=strFilePath, _
msoFileViewType:=msoFileDialogViewList, _
strButtonCaption:="OK")
With objFileDialog
.Filters.Clear ' remove all file types
.Filters.Add "Word Documents", "*.doc", 1 ' show only Word documents
If .Show = USER_CLICKED_BUTTON Then
' remove the file path from the value returned by dialog box.
' put that file name in the FileName field.
Me.FileName.Value = Replace(.SelectedItems.Item(Index:=1), strFilePath, "")
End If
End With
Proc_Exit:
Exit Sub
Proc_Error:
MsgBox Err.Description
Resume Proc_Exit
End Sub
Public Function BuildCommonDialogBox(ByVal msoDialogType As MsoFileDialogType, _
ByVal strTitleCaption As String, _
ByVal strFileName As String, _
ByVal msoFileViewType As MsoFileDialogView, _
ByVal strButtonCaption As String, _
Optional ByVal blnSelectMultipleFiles As Boolean = False) _
As FileDialog
' This function references the Microsoft Office 10.0 Object Library.
Dim obj As FileDialog
Set obj = Application.FileDialog(DialogType:=msoDialogType)
With obj
.Title = strTitleCaption
.InitialFileName = strFileName
.InitialView = msoFileViewType
.ButtonName = strButtonCaption
.AllowMultiSelect = blnSelectMultipleFiles
End With
Set BuildCommonDialogBox = obj
End Function