Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4274
  • Last Modified:

Get file path using dialog open box

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
vishalarya
Asked:
vishalarya
  • 2
1 Solution
 
Jeroen RosinkCommented:
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
 
Wayne Taylor (webtubbs)Commented:
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
 
Wayne Taylor (webtubbs)Commented:
Umm, I thought this was for Access? GetOpenFilename doesn't work in Access.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now