Solved

Get file path using dialog open box

Posted on 2007-11-28
3
4,233 Views
Last Modified: 2013-11-28
I'm using MS Access VBA and would like to open a dialog open box, similar to MS Excel's "GetOpenFileName" function for the user to select a specific file.  I then would like to capture the complete path and store it in a local table.  My code is below, though I'm not sure why MS Access is not understanding FileDialog function:

Dim dlgOpen As FileDialog

Set dlgOpen = Application.FileDialog(FileDialogType:=msoFileDialogOpen)

With dlgOpen
    .AllowMultiSelect = False
    .Show
End With

Thanks,
Vishalarya
0
Comment
Question by:vishalarya
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
Jeroen Rosink earned 500 total points
ID: 20371591
Hello Vishalarya,

you might try something like:
flname = Application.GetOpenFilename( _
    Title:="Please select any file from the folder that contains the data, then click Open.")
If flname = False Then Exit Sub


the variable "flname" contains the selecte filename including path, you can use this for your object.

I hope this works for you
regards,
Jeroen
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20371662
Hi vishalarya,

If you add a reference to MS Office (Tools > References), you can use that code, then get the selected path from the SelectedItems property....

    Dim dlgOpen As FileDialog
    Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
    With dlgOpen
        .AllowMultiSelect = False
        .Show
        MsgBox .SelectedItems(1)
    End With

Regards,

Wayne
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20371704
Umm, I thought this was for Access? GetOpenFilename doesn't work in Access.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

821 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