?
Solved

Access equivalent of Excel:  strVarName = Application.GetOpenFilename( fileFilter:="Excel Files (*.xls), *.xls")

Posted on 2006-11-17
9
Medium Priority
?
1,151 Views
Last Modified: 2007-12-19
In VBA for Excel, when I want to get the user to select a file and assign its path and name to a variable I use the command:
strVarName = Application.GetOpenFilename( fileFilter:="Excel Files (*.xls), *.xls")
Is there an Access equivalent?
0
Comment
Question by:Rob4077
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 664 total points
ID: 17965606
strVarName = Application.GetOpenFilename( fileFilter:="Access databases", "*.mdb")
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17965631
or you can give this a whirl (from Excel VBA,so you may have to modify it slightly)...

    'Declare a variable as a FileDialog object.
    Dim fd As Office.FileDialog
   
    Dim xla As Excel.Application
    Set xla = GetObject(, "Excel.Application")

    'Create a FileDialog object as a File Picker dialog box.
    Set fd = xla.FileDialog(Office.msoFileDialogOpen)
   
    fd.AllowMultiSelect = True
   
    fd.Title = strTitle
   
    fd.InitialView = Office.msoFileDialogViewList
   
    fd.Filters.Clear
    fd.Filters.Add "Access databases", "*.mdb"
    fd.Filters.Add "Excel Files (*.xls), "*.xls")
    fd.Filters.Add "Whatever Files (*.wha), "*.wha")
   
    fd.Show
0
 
LVL 44

Assisted Solution

by:Leigh Purvis
Leigh Purvis earned 668 total points
ID: 17965818
Or just make your own

Function fGetFileName(strFileDesc as String, strExt as String) As String
   
    Dim objFD As Object
   
    Set objFD = Application.FileDialog(msoFileDialogOpen)
   
    With objFD
        .Filters.Add strFileDesc, strExt, 2
        .Show
    End With
   
    fGetFileName = obj.SelectedItems(1)
   
End Function
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Accepted Solution

by:
stevbe earned 668 total points
ID: 17971047
the above solutions only work if your using mde format ... they do not work for mde. You can use code from the following link ... it looks really complicated but once you have that in a seperate module, using it is very similar (almost exact) to what you are doing now.

http://www.mvps.org/access/api/api0001.htm

Steve

0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17971118
Yeah - that's the standard solution (courtesy of the Access Web)... but it's not the "equivalent"  ;-)

The above fGetFileName should work in an MDE though.
And indeed - in runtime (assuming there are some Office components present with it).

What you might struggle with is needing a reference to the Office library - but that'd be due to the constant used...

Set objFD = Application.FileDialog(1)

should do that...
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17971602
(FWIW I use the API though ;-)
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17971751
we have Office on all our PCs but only Access Runtime, distributed mde, and the above (non-API) does not work.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17971835
Does it work on your machine with the Runtime startup command line switch Steve?
0
 

Author Comment

by:Rob4077
ID: 17977231
Thanks for all the suggestions. It seems there are many solutions to my question. I have chosen the code supplied by stevebe but I am sure that all the other solutions have their merits so I will share the points around. Thanks for your help.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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 …
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

801 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