?
Solved

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

Posted on 2006-11-17
9
Medium Priority
?
1,182 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

755 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