• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2006
  • Last Modified:

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
0
Rayne
Asked:
Rayne
2 Solutions
 
GrahamSkanRetiredCommented:
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
 
Rey Obrero (Capricorn1)Commented:
try adding

microsoft office 14 object library

to your references

from vba window
Tools > references
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
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
 
Rey Obrero (Capricorn1)Commented:
go to this folder

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

and see if you have the file MSO.dll
0
 
RayneAuthor Commented:
Here is another one:
http://www.experts-exchange.com/Database/MS_Access/Q_28412392.html
if you are interested
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now