Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ms access get file name selected from FileDialog

Tags:

vba

ms-access

This is my code, and I want to know how to get name of file selected

Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = True
If f.Show Then
    For i = 1 To f.SelectedItems.Count
        MsgBox f.SelectedItems(i)
    Next
EndIf
like image 799
Mahyar Avatar asked Apr 30 '12 11:04

Mahyar


1 Answers

You mean like this?

Sub Sample()
    Dim f As Object

    Set f = Application.FileDialog(3)

    f.AllowMultiSelect = True

    If f.Show Then
        For i = 1 To f.SelectedItems.Count
            MsgBox Filename(f.SelectedItems(i))
        Next
    End If
End Sub

Public Function Filename(ByVal strPath As String) As String
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
        Filename = Filename(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
    End If
End Function
like image 162
Siddharth Rout Avatar answered Sep 20 '22 12:09

Siddharth Rout