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
Solved

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

Posted on 2006-11-17
9
1,105 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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
 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

856 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