[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2006-11-17
9
Medium Priority
?
1,173 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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 …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

650 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