FileDialog Box in Access 2010 VBA

Hello
I am trying to open a excel file from access 2010 file. This code is not working as its giving errors.


Option Compare Database
Sub b()


Dim fDialog As FileDialog
Dim varFile As Variant
Dim FilePath As String
Dim FileName As String
Dim fs As Object
Dim SavePath As String
Dim OpenFile As Variant
Set fs = Interaction.CreateObject("Scripting.FilesystemObject")
'Declare SavePath for Documents
SavePath = "\\Path\to\share\Directory\"
 
 
 
'Set up the File Dialog
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
 
With fDialog
    'Do not Allow user to select multiple files
    .AllowMultiSelect = False
 
    'Set the title of the Dialog box
    .Title = "Please select the file you want to move"
    
    'Clear our the current filters and add our own
    .Filters.Clear
    .Filters.Add "Adobe PDF", "*.PDF"
    .Filters.Add "All Files", "*.*"
    
    'Show the Dialog box. If the .Show method returns True, the
    'user picked a file. If the .Show method returns
    'False, the user clicked cancel.
    If .Show = True Then
        'Display what file the user picked
        For Each varFile In .SelectedItems
        Me.DocumentLocation.Value = SavePath
        'Copy the File to the Share
        fs.Copyfile varFile, SavePath
        MsgBox ("The file you selected is - " & varFile)
       
        Set fs = Nothing
        
        Next
    'The User Pressed the Cancel button
    Else
        MsgBox ("You clicked cancel!")
    End If
End With



End Sub

Open in new window




What change do I need to do to make this work or any other alternatives you may suggest.
compileErr.png
RayneAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
go to this folder

C:\Program Files (x86)\Common Files\microsoft shared\OFFICE14

and see if you have the file MSO.dll
0
 
GrahamSkanConnect With a Mentor RetiredCommented:
The error is: "User-defined type not defined."
You need to set a reference to the Microsoft Office library

Also the code appears to be looking for PDF files instead of Excel fines (Line 30)
0
 
Dale FyeCommented:
do you have a reference set to the

Microsoft Office XX.X Object Library
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Rey Obrero (Capricorn1)Commented:
try adding

microsoft office 14 object library

to your references

from vba window
Tools > references
0
 
RayneAuthor Commented:
If its alphabetical order, I am not seeing the office object library – can you?
library-reference.png
0
 
Rey Obrero (Capricorn1)Commented:
how about the selected references portion? is it not on the list?
0
 
RayneAuthor Commented:
0
 
RayneAuthor Commented:
Here is another one:
http://www.experts-exchange.com/Database/MS_Access/Q_28412392.html
if you are interested
0
All Courses

From novice to tech pro — start learning today.