Solved

FileDialog Box in Access 2010 VBA

Posted on 2014-04-14
8
1,723 Views
Last Modified: 2014-04-14
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
Comment
Question by:Rayne
8 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 250 total points
ID: 39999709
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
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39999713
do you have a reference set to the

Microsoft Office XX.X Object Library
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39999723
try adding

microsoft office 14 object library

to your references

from vba window
Tools > references
0
 

Author Comment

by:Rayne
ID: 39999735
If its alphabetical order, I am not seeing the office object library – can you?
library-reference.png
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 39999749
how about the selected references portion? is it not on the list?
0
 

Author Comment

by:Rayne
ID: 39999859
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 39999912
go to this folder

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

and see if you have the file MSO.dll
0
 

Author Comment

by:Rayne
ID: 40000049
Here is another one:
http://www.experts-exchange.com/Database/MS_Access/Q_28412392.html
if you are interested
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now