Solved

# FileDialog Box in Access 2010 VBA

Posted on 2014-04-14
1,773 Views
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

'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


What change do I need to do to make this work or any other alternatives you may suggest.
compileErr.png
0
Question by:Rayne

LVL 76

Assisted Solution

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

ID: 39999713
do you have a reference set to the

Microsoft Office XX.X Object Library
0

LVL 120

Expert Comment

ID: 39999723

microsoft office 14 object library

from vba window
Tools > references
0

Author Comment

ID: 39999735
If its alphabetical order, I am not seeing the office object library – can you?
library-reference.png
0

LVL 120

Expert Comment

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

Author Comment

ID: 39999859
0

LVL 120

Accepted Solution

Rey Obrero (Capricorn1) 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

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

## Featured Post

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …