FileDialog Not Working in Access 2010 (1 Viewer)

dferreira

Registered User.
Local time
Today, 01:16
Joined
Sep 13, 2011
Messages
25
I am trying to allow the user the capability to browse to a file to import that file into access. I found code for it, but it still does not work. I can't find the reference that is recommended. Help????
 

shadow9449

Registered User.
Local time
Today, 01:16
Joined
Mar 5, 2004
Messages
1,037
Are you using the 64 bit edition? Some API calls don't work in the 64 bit edition unless you use the appropriate call.

SHADOW
 

dferreira

Registered User.
Local time
Today, 01:16
Joined
Sep 13, 2011
Messages
25
hiw do I know if it is 64 bit?
 

penguino29

Registered User.
Local time
Today, 06:16
Joined
Dec 23, 2010
Messages
52
Hi dferreira,

In the past, we used Windows API to callup the common dialog box in order to obtain a filepath. This has become problematic with 32 and 64 bit versions of windows.

Its much easier nowadays to use the Microsoft Office FileDialog because its independent of the OS. (I've tried it on Win7x64 and x86)

The reference is here:

http://msdn.microsoft.com/en-us/library/aa190816(v=office.10).aspx

(you will need to copy the code from the article and stick it in a module)

And make sure you add MS Office Library reference. To do this: in the VBA project window, on the menu, click TOOLS, REFERENCES, then scroll down the list and find "Microsoft Office 14.0 Object Library" and check the tickbox.

(You may have difference version number instead of 14.0, depending on which version of office you have installed)

If you need some sample codes, just come back here and ask.
 

dferreira

Registered User.
Local time
Today, 01:16
Joined
Sep 13, 2011
Messages
25
Thank You, Thank You!!!!!! I have spent so much time tring to make this work! If you were here I would kiss you!

:):):):):)
 

penguino29

Registered User.
Local time
Today, 06:16
Joined
Dec 23, 2010
Messages
52
You are welcome - we are all here to help! :D

I was tearing my hair out using comdlg32.dll before, using the MS Office File Dialog is much easier.

Come back here if you have any problems.
 

dferreira

Registered User.
Local time
Today, 01:16
Joined
Sep 13, 2011
Messages
25
Can someone tell me how to import the file using the File Dialog now that I have that code working.
 

ulieq

Registered User.
Local time
Yesterday, 22:16
Joined
Dec 15, 2011
Messages
28
I would love detailed instructions in how to make this work. Copy and paste to module means nothing to me. Thanks.
 

penguino29

Registered User.
Local time
Today, 06:16
Joined
Dec 23, 2010
Messages
52
Hi ulieq and dferreira,

Thanks for bumping the thread. Apology for my absence.

I've done some revision recently, and there is actually an elegant way to do it. The following is known with work in in Access 2007 and 2010.

Put the following code under an onClick event of a button.

Code:
Dim f   As Object
Set f = Application.FileDialog(3)
 
With f
    ' Allow Mulitple Selections
    .AllowMultiSelect = True
    
    ' Set the title of the dialog box. '
    .Title = "Please select one or more files"
    
    ' Clear out the current filters, and add our own.'
    .Filters.Clear
    .Filters.Add "Access Databases", "*.MDB"
    .Filters.Add "Access Projects", "*.ADP"
    .Filters.Add "All Files", "*.*"
End With  '--- f

' Call .Show and show the dialog. If the method returns True, the user picked at least one file.
' If the method returns False, the user clicked Cancel.
If f.Show Then
    MsgBox f.SelectedItems.Count & " file(s) were chosen."

    ' Display the full path to each file that was selected
    Dim i As Integer
    For i = 1 To f.SelectedItems.Count
        MsgBox f.SelectedItems(i)
    Next i
End If

Full credits and details are from the original articles here:-

http://stackoverflow.com/questions/1091484/how-to-show-open-file-dialog-in-access-2007-vba

http://stackoverflow.com/questions/4813598/using-the-browse-for-file-dialog-in-access-vba
 

shadow9449

Registered User.
Local time
Today, 01:16
Joined
Mar 5, 2004
Messages
1,037
I did a search for the FileDialog and I found this Microsoft page:

http://support.microsoft.com/kb/279508

According to the Summary, the FileDialog does not work with the Access Runtime. Does anyone know if this is true for later versions of Access? If so, it's a SERIOUS limitation.

Thanks

SHADOW
 

penguino29

Registered User.
Local time
Today, 06:16
Joined
Dec 23, 2010
Messages
52
Hi shadow9449,

Thanks for looking up and pointing out the possible issue. According to the links in my post, FileDialog works for 2007 runtime - although I cannot vouch for it (be it 2007 or 2010) as I haven't tried it myself.

So in most cases the code should work. Your mileage may vary. :)
 

ulieq

Registered User.
Local time
Yesterday, 22:16
Joined
Dec 15, 2011
Messages
28
i still cannot get this to work. I use 32bit office 2010 and windows xp. I put the code under the onclick event of a button. Does the name of the button have to be changed to something?
 

shadow9449

Registered User.
Local time
Today, 01:16
Joined
Mar 5, 2004
Messages
1,037
penguino29 :

I didn't see any mention either way of whether it works in runtime versions in those articles.

I wonder if anyone has any experience either way?

SHADOW
 

ulieq

Registered User.
Local time
Yesterday, 22:16
Joined
Dec 15, 2011
Messages
28
Actually, I got an error "Invalid Outside procedure"
 

penguino29

Registered User.
Local time
Today, 06:16
Joined
Dec 23, 2010
Messages
52
Hi ulieq,

You need to put the code inside, in between the "Private Sub" and "End Sub" of a button's code. It should work. Please try again and report back.


Shadow9449:

from http://stackoverflow.com/questions/1091484/how-to-show-open-file-dialog-in-access-2007-vba
My comments on Renaud Bompuis's answer messed up.

Actually, you can use late binding, and the reference to the 11.0 object library is not required.

The following code will work without any references:

Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
f.Show

MsgBox "file choosen = " & f.SelectedItems.Count
Note that the above works well in the runtime also.
 

ulieq

Registered User.
Local time
Yesterday, 22:16
Joined
Dec 15, 2011
Messages
28
Thanks. I got that to work. Now how do I get that file path to be inserted into the text box?
 

penguino29

Registered User.
Local time
Today, 06:16
Joined
Dec 23, 2010
Messages
52
Hi ulieq,

As you can see from the sample code, the variable

Code:
f.SelectedItems(i)

contains the file path. You simply assign that to a text box.

Code:
me!myTextbox1 = f.SelectedItems(i)
 

ulieq

Registered User.
Local time
Yesterday, 22:16
Joined
Dec 15, 2011
Messages
28
Nice. Next: How to use relative file paths FROM the datbase backend? ^_^ thanks!
 

ulieq

Registered User.
Local time
Yesterday, 22:16
Joined
Dec 15, 2011
Messages
28
This method only enters data into an unbound textbox. How do I save that textbox to the correct field?
 

Users who are viewing this thread

Top Bottom