Solved

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

Posted on 2006-11-17
9
1,063 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 65

Assisted Solution

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

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 167 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
 
LVL 39

Accepted Solution

by:
stevbe earned 167 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now